code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <iostream>
#include <climits>
using namespace std;
#define int long long
const int INF=1e18;
const int MAX_V=2000;
int v,g[MAX_V][MAX_V],r;
void warshall(){
for(int k=0;k<v;k++)
for(int i=0;i<v;i++)
for(int j=0;j<v;j++) g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
}
signed main(){
int e;
cin>>v>>e;
for(int i=0;i<v;i++) for(int j=0;j<v;j++) g[i][j]=i==j?0:INF;
for(int i=0,a,b,c;i<e&&cin>>a>>b>>c;i++) g[a][b]=c;
warshall();
//for(int i=0;i<v;i++) for(int j=0;j<v;j++) if(INF/2<g[i][j]&&g[i][j]<INF) r++;
for(int i=0;i<v;i++) if(g[i][i]) r++;
if(r){
cout<<"NEGATIVE CYCLE"<<endl;
return 0;
}
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
if(j) cout<<" ";
if(g[i][j]>=INF/2) cout<<"INF";
else cout<<g[i][j];
}
cout<<endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
static const int SIZE = 101;
static const long long int INF = 1e18;
long long int d[SIZE][SIZE] = { 0 };
void solve()
{
for (int i = 0; i < SIZE; ++i)
{
for (int j = 0; j < SIZE; ++j)
{
d[i][j] = INF;
}
d[i][i] = 0;
}
int V, E;
cin >> V >> E;
for (int i = 0; i < E; ++i)
{
int from, to, cost;
cin >> from >> to >> cost;
d[from][to] = cost;
}
for (int k = 0; k < V; ++k)
{
for (int i = 0; i < V; ++i)
{
for (int j = 0; j < V; ++j)
{
if (d[i][k] != INF && d[k][j] != INF)
{
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
bool isNegative = false;
for (int i = 0; i < V; ++i)
{
if (d[i][i] < 0)
{
cout << "NEGATIVE CYCLE" << endl;
return;
}
}
for (int i = 0; i < V; ++i)
{
for (int j = 0; j < V; ++j)
{
if (j)
{
cout << " ";
}
if (d[i][j] == INF)
{
cout << "INF";
}
else
{
cout << d[i][j];
}
}
cout << endl;
}
}
int main()
{
solve();
return(0);
} | 1 |
// Hail god Yato
#include <bits/stdc++.h>
using namespace std;
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
ll a, b;
cin>>a>>b;
cout<<a*b;
}
int main(){
hs;
ll t;
t=1;
// cin>>t;
for (int i=1; i<=t; i++){
//cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void abc_160a();
void abc_161a();
void abc_162a();
void abc_163a();
void abc_164a();
void abc_165a();
void abc_166a();
void abc_167a();
void abc_168a();
void abc_169();
int main()
{
//abc_160a();
//abc_161a();
//abc_162a();
//abc_163a();
//abc_164a();
//abc_165a();
//abc_166a();
//abc_167a();
//abc_168a();
abc_169();
}
void abc_160a()
{
string S;
cin >> S;
if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
else cout << "No\n";
}
void swap(int& a, int& b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
}
void abc_161a()
{
int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << "\n";
}
void abc_162a()
{
string s;
cin >> s;
for (char c : s)
{
if (c == '7')
{
cout << "Yes\n";
return;
}
}
cout << "No\n";
}
void abc_163a()
{
int R;
cin >> R;
cout << (double)(2 * R * M_PI);
}
void abc_164a()
{
int s, w;
cin >> s >> w;
if (s <= w) cout << "unsafe\n";
else cout << "safe\n";
}
void abc_165a()
{
int k, a, b;
cin >> k >> a >> b;
for (int i = a; i <= b; ++i)
{
if (i % k == 0)
{
cout << "OK\n";
return;
}
}
cout << "NG\n";
}
void abc_166a()
{
string s;
cin >> s;
if (s == "ABC") cout << "ARC\n";
if (s == "ARC") cout << "ABC\n";
}
void abc_167a()
{
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i)
{
if (s[i] != t[i])
{
cout << "No\n";
return;
}
}
if ('a' <= t[t.size() - 1] && t[t.size() - 1] <= 'z') cout << "Yes\n";
else cout << "No\n";
}
void abc_168a()
{
string s;
cin >> s;
if (s[s.size() - 1] == '3') cout << "bon\n";
else if (s[s.size() - 1] == '0' ||
s[s.size() - 1] == '1' ||
s[s.size() - 1] == '6' ||
s[s.size() - 1] == '8') cout << "pon\n";
else cout << "hon\n";
}
void abc_169()
{
int a, b;
cin >> a >> b;
cout << a * b << "\n";
}
| 1 |
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;
#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()
string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }
#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif
const ll inf = (ll)1e18 + 5;
const ll mod = 1e9+7;
const ll nax = 100500;
ll F[nax], INVF[nax];
ll pow(ll a, ll b) {
if (b == 0) return 1;
ll h = pow(a, b/2);
ll ans = b % 2 ? h * h % mod * a : h * h;
ans %= mod;
return ans;
}
ll ncr(ll n, ll r) {
// n! / r! / (n-r)!
ll ans = F[n];
ans *= INVF[r];
ans %= mod;
ans *= INVF[n-r];
ans %= mod;
return ans;
}
void solve() {
ll n, m;
in(n, m);
F[0] = 1;
REP(i,1,nax) F[i] = (F[i-1] * i) % mod;
REP(i,0,nax) INVF[i] = pow(F[i], mod-2);
map<ll,ll> factors;
ll f = 2;
while (m != 1 && f*f <= m) {
while (m % f == 0) {
factors[f]++;
m /= f;
}
f++;
}
if (m != 1) factors[m]++;
ll ans = 1;
for (PLL a : factors) {
ans *= ncr(a.second + n - 1, a.second) % mod;
ans %= mod;
}
cout << ans << endl;
}
signed main() {
ll t = 1;
REP(i,0,t) solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
return 1;
else if(y%2==0)
return (f(x,y/2)*f(x,y/2))%mod;
else
return (f(x,y/2)*((x*f(x,y/2))%mod))%mod;
}
int64_t comb(int64_t x,int64_t y){
int64_t ans=1;
for(int64_t i=y;1<=i;i--){
ans=(f(i,mod-2)*((ans*(x-y+i))%mod))%mod;
}return ans;
}
int main(){
int64_t N,M;
cin>>N>>M;
int64_t m=M;
vector<int64_t>A={};
for(int64_t i=2;i*i<=m;i++){
if(M%i==0){
int64_t a=0;
while(M%i==0){
M/=i; a++;
}A.push_back(a);
}
}if(M!=1)
A.push_back(1);
int L=A.size();
int64_t ans=1;
for(int i=0;i<L;i++){
int64_t a=A.at(i);
ans=(ans*comb(N-1+a,a))%mod;
}cout<<ans<<endl;
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int nMember, nNeedMember;
while(cin >> nMember >> nNeedMember, nMember | nNeedMember) {
vector<int> dates(100, 0); //one base
for(int i = 0; i < nMember; ++i) {
int ndate;
cin >> ndate;
for(int j = 0; j < ndate; ++j) {
int date;
cin >> date;
++dates[date];
}
}
auto max_itr = max_element(dates.begin(), dates.end());
cout << ((*max_itr >= nNeedMember) ? distance(dates.begin(), max_itr) : 0) << endl;
}
return 0;
} | #include<stdio.h>
#include<algorithm>
using namespace std;
char map[15][15],moji[15];
void func(int ,int);
int main(void){
int i,j;
while(1){
for(i=0;i<12;i++){
if(scanf("%s",map[i])==EOF){
return 0;
}
}
/*for(i=0;i<=12;i++){
printf("%s",map[i]);
}
printf("\n");*/
int cnt=0;
for(i=0;i<12;i++){
for(j=0;j<12;j++){
if(map[i][j]=='1'){
map[i][j]=0;
func(i,j);
cnt++;
}
}
}
printf("%d\n",cnt);
}
}
void func(int y,int x){
int i,j;
int xx,yy;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
for(i=0;i<4;i++){
xx=x+dx[i];
yy=y+dy[i];
if(map[yy][xx]=='1' && xx<=12 && xx>=0 && yy<=12 && yy>=0){
map[yy][xx]=0;
func(yy,xx);
}
}
} | 0 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;
int main(void){
int N,Q;
cin >> N >> Q;
string S;
cin >> S;
vector<int> ac(S.size(),0);
int cnt = 0;
for(int i =1; i <= S.size(); i++){
if(S[i-1] == 'A' && S[i] == 'C'){
cnt++;
}
ac[i] = cnt;
}
for(int i = 0; i < Q; i++){
int l, r;
cin >> l >> r;
cout << ac[r-1] - ac[l-1] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
int main(){
ll n, q;
string s;
cin >> n >> q >> s;
vector<ll> dp(n, 0);
for(ll i = 0; i < n-1; i++){
if(s[i] == 'A' && s[i+1] == 'C'){
dp[i+1] = (dp[i] + 1);
}
else{
dp[i+1] = dp[i];
}
}
while(q){
ll l,r;
cin >> l >> r;
cout << dp[r-1] - dp[l-1] << endl;
q--;
}
} | 1 |
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}
int main(){
string S;
cin >> S;
string F = "FESTIVAL";
rep(i, F.size()) S.pop_back();
Cout(S);
}
| #include<iostream>
#include<cstring>
using namespace std;
int main()
{
char n[10];
cin>>n;
for(int i=0;i<strlen(n);i++)
{
if(n[i]=='A'&&n[i+1]=='C')
{
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
} | 0 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;
#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//
int main()
{
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
string s;
cin >> s;
int len = s.size();
if(len < 26){
int vis[26] = {};
for(int i = 0 ; i < len ; ++i)
vis[s[i]-'a']++;
for(int i = 0 ; i < 26 ; ++i)
if(!vis[i])
return cout << s << char(i+'a') << "\n" , 0;
}
else{
string temp = "";
for(int i = 25 ; i >= 0 ; --i)
temp += char(i + 'a');
if(s == temp)
cout << "-1\n";
else{
set < char > st;
for(int i = 25 ; i >= 0 ; --i){
st.insert(s[i]);
if(s[i-1] < s[i]){ // abc
char add = *st.upper_bound(s[i-1]);
cout << s.substr(0 , i-1) << add << "\n";
break;
}
}
}
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
using LL = long long;
using P = pair<int,int>;
const int Max_N=1010;
int A[Max_N][Max_N];
int main(){
int N;
cin >> N;
rep(i,N){
rep(j,N-1){
int a;
cin >> a;
a--;
A[i][j]=a;
}
}
vector<int> op(N);
int ans=0, sum=N;
queue<int> q1, q2;
rep(a,N){
int n=A[a][0], m=op[n];
if(n<a) continue;
if(A[n][m]==a) q1.push(a);
}
while(sum){
ans++;
if(q1.empty()){
cout << -1 << endl;
return 0;
}
while(!q1.empty()){
int a=q1.front(); q1.pop();
int n=A[a][op[a]], m=op[n];
q2.push(a), q2.push(n);
op[a]++; op[n]++;
if(op[a]==N-1) op[a]=-1, sum--;
if(op[n]==N-1) op[n]=-1, sum--;
}
vector<bool> pushed(N);
while(!q2.empty()){
int a=q2.front(); q2.pop();
if(op[a]==-1) continue;
int n=A[a][op[a]], m=op[n];
if(pushed[n]) continue;
if(A[n][m]==a) q1.push(a), pushed[a]=true;
}
}
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }
template <typename T>
void view(const std::vector<T> &v)
{
for (const auto &e : v)
{
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
for (const auto &v : vv)
{
view(v);
}
}
#pragma endregion
int main()
{
int n;
cin >> n;
ll keta = 0;
ll sum = 0;
rep(i, n)
{
ll a, b;
cin >> a >> b;
sum += a * b;
keta += b;
}
ll total = (sum - 1) / 9;
ll ans = keta - 1 + total;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int fact(int n){
if(n == 1) return 1;
else return n * fact(n-1);
}
int main(){
int n;
cin >> n;
vector<pair<int,int>> array(n);
for(int i=0;i<n;i++) cin >> array.at(i).first >> array.at(i).second;
sort(array.begin(),array.end());
double sum = 0;
do{
for(int i=0;i<n-1;i++){
int d2 = (array.at(i+1).first - array.at(i).first) * (array.at(i+1).first - array.at(i).first) +
(array.at(i+1).second - array.at(i).second) * (array.at(i+1).second - array.at(i).second);
double d = sqrt((double)d2);
sum += d;
}
} while(next_permutation(array.begin(),array.end()));
int kaijou = fact(n);
double ave = sum / (double)kaijou;
printf("%.10lf \n",ave);
}
| 0 |
#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
void call(int n){
for(int i=1;i<=n;i++){
stringstream ss;
ss<<i;
char c[8];
ss>>c;
if(i%3==0||strstr(c,"3"))
cout<<" "<<i;
}
cout<<endl;
}
int main(){ _;
int n;cin>>n;
call(n);
} | #include <iostream>
using namespace std;
void call(int num) {
for (int i = 1; i <= num; i++) {
int x = i;
//3????????°?????¨???
if (x % 3 == 0) {
cout << " " << i;
}
//3???????????°?????¨???
else {
do {
if (x % 10 == 3) {
cout << " " << i;
break;
}
x/= 10;
} while (x);
}
}
cout << endl;
}
int main(){
int num;
cin >> num;
call(num);
return 0;
} | 1 |
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD=1e9+7;
#define MAX 1000001
long fac[MAX], finv[MAX], inv[MAX];
void fact() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; ++i){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long comb(ll n, ll k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int main(){
ios::sync_with_stdio(false);
fact();
ll N,A,B,C,D;
cin>>N>>A>>B>>C>>D;
vector<vector<ll>> g(1001, vector<ll>(1001, -1));
//G(i,a)はi人のグル×aの作り方
function<ll(ll,ll)> G = [&](ll i,ll a){
if(a<=1)return 1LL;
else if(g[i][a]!=-1)return g[i][a];
else return g[i][a]=(((G(i,a-1)*comb(i*a,i))%MOD)*modinv(a,MOD))%MOD;
};
vector<vector<ll>> dp(B+1, vector<ll>(N+1, -1));
//F(a,x)はa人以上B人以下のグループのみを使ってx人を分ける場合の数
function<ll(ll,ll)> F = [&](ll a, ll x){
if(x==0)return 1LL;
else if(dp[a][x]!=-1)return dp[a][x];
else if(a==B){
if(x%B==0&&C<=(x/B)&&(x/B)<=D)return dp[B][x]=G(B,x/B);
else return dp[B][x]=0;
}
else{
//Fa==0
ll ret=F(a+1,x);
//FaがCからD
for(ll i=C;i<=D&&x-i*a>=0;++i){
ret+=(((F(a+1,x-i*a)*G(a,i))%MOD)*comb(x,i*a))%MOD;
ret%=MOD;
}
return dp[a][x]=ret;}
};
cout<<F(A,N)<<endl;
return 0;
}
| #include <iostream>
#include <algorithm>
const int MAX_N = 100;
const int INF = 999999999;
using namespace std;
int dp[MAX_N+1][MAX_N+1];
int p[MAX_N+1];
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> p[i-1] >> p[i];
}
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n-l+1; i++) {
int j = i+l-1;
dp[i][j] = INF;
for (int k = i; k <= j-1; k++) {
dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j] + p[i-1]*p[k]*p[j]);
}
}
}
cout << dp[1][n] << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
signed main(){
string s,t;
cin>>s;
t = s;
vector<int> alp(26);
for(auto c:s)alp[c-'a']++;
string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzz";
auto chmin = [](auto& a,auto b){if(a>b)a=b;};
while(1){
for(int i=0;i<26;++i)if(alp[i]==0){
string tmp = s;
tmp += ('a'+i);
if(t<tmp){
chmin(ans,tmp);
}
}
if(s.empty())break;
alp[s.back()-'a']--;
s.pop_back();
}
cout<<(ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzz"?"-1":ans)<<endl;
} | #include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = (int)s.size();
if (n < 26) {
map<char, bool> mp;
for (auto&& c : s) {
mp[c] = true;
}
for (char c = 'a'; c <= 'z'; c++) {
if (!mp.count(c)) {
s += c;
break;
}
}
cout << s << '\n';
} else {
if (s == "zyxwvutsrqponmlkjihgfedcba") {
cout << -1 << '\n';
} else {
string ans;
for (int i = n - 1; i > 0; i--) {
if (s[i - 1] < s[i]) {
ans = s.substr(0, i);
break;
}
}
map<char, bool> mp;
for (auto&& c : ans) {
mp[c] = true;
}
debug(ans);
for (char c = ans.back() + 1; c <= 'z'; c++) {
if (!mp.count(c)) {
ans.pop_back();
ans += c;
break;
}
}
cout << ans << '\n';
}
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
int main() {
int n,k;
while(cin >> n >> k, n && k) {
long long INF = 1e10;
vector<vector<long long>> dist(n, vector<long long>(n, INF));
for(int i = 0;i < n;i++) dist[i][i] = 0;
for(int q = 0;q < k;q++) {
int Q;
cin >> Q;
if(Q == 0) {
int a, b;
cin >> a >> b;
a--;
b--;
if(dist[a][b] < INF) {
cout << dist[a][b] << endl;
}
else {
cout << -1 << endl;
}
}
else {
long long c,d,e;
cin >> c >> d >> e;
c--;
d--;
dist[c][d] = min(dist[c][d], e);
dist[d][c] = min(dist[d][c], e);
for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) {
dist[i][j] = min(dist[i][j], dist[i][c] + dist[c][d] + dist[d][j]);
}
for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) {
dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][c] + dist[c][j]);
}
}
}
}
}
| #include <cstdio>
#include <algorithm>
using namespace std;
#define INF (1<<27)
int cost[100][100];
int main() {
int n,k;
while(scanf("%d %d",&n,&k),n) {
fill((int*)cost,(int*)(cost+100),INF);
for(int i=0;i<k;i++) {
int a,b,c;
scanf("%d",&a);
if(a==0) {
scanf("%d %d",&a,&b);
if(cost[a-1][b-1]==INF)
printf("-1\n");
else
printf("%d\n",cost[a-1][b-1]);
}else {
scanf("%d %d %d",&a,&b,&c);
if(cost[a-1][b-1]>c) {
cost[a-1][b-1]=cost[b-1][a-1]=c;
for(int k=0;k<n;k++) {
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
}
}
}
}
}
}
}
} | 1 |
#include <stdio.h>
struct Dice
{
int n[6];
};
Dice InputDice()
{
Dice d;
for(int i = 0; i < 6; ++i)
{
scanf("%d", &d.n[i]);
}
return d;
}
Dice SetDice(int a, int b, int c, int d, int e, int f)
{
Dice dice;
dice.n[0] = a;
dice.n[1] = b;
dice.n[2] = c;
dice.n[3] = d;
dice.n[4] = e;
dice.n[5] = f;
return dice;
}
Dice Roll(Dice dice, char dir)
{
switch(dir)
{
case 'N':
return SetDice(dice.n[1], dice.n[5], dice.n[2], dice.n[3], dice.n[0], dice.n[4]);
case 'S':
return SetDice(dice.n[4], dice.n[0], dice.n[2], dice.n[3], dice.n[5], dice.n[1]);
case 'W':
return SetDice(dice.n[2], dice.n[1], dice.n[5], dice.n[0], dice.n[4], dice.n[3]);
case 'E':
return SetDice(dice.n[3], dice.n[1], dice.n[0], dice.n[5], dice.n[4], dice.n[2]);
}
}
bool IsSame(Dice a, Dice b)
{
for(int i = 0; i < 6; ++i)
{
if(a.n[i] != b.n[i])
{
return false;
}
}
return true;
}
bool IsEqual(Dice a, Dice b)
{
char cmd[25] = "NNNNWNNNWNNNENNNENNNWNNN";
for(int i = 0; i < 24; ++i)
{
b = Roll(b, cmd[i]);
if(IsSame(a, b))
{
return true;
}
}
return false;
}
int FindSide(Dice a, int top, int front)
{
char cmd[25] = "NNNNWNNNWNNNENNNENNNWNNN";
for(int i = 0; i < 24; ++i)
{
a = Roll(a, cmd[i]);
if(a.n[0] == top && a.n[1] == front)
{
return a.n[2];
}
}
return -1;
}
int main()
{
int N;
scanf("%d", &N);
Dice D[128];
bool ans = true;
for(int i = 0; i < N; ++i)
{
D[i] = InputDice();
for(int j = 0; j < i && ans; ++j)
{
if(IsEqual(D[i], D[j]))
{
ans = false;
}
}
}
if(ans)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}
| #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
LL kk=0,f=1;
char cc=getchar();
while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
return kk*f;
}
LL a[2000222],dp[4],n,sum[2000222];
#define P(x) (x%3+3)%3
int main()
{
n=read();
for(int i=1;i<=n;++i)
{
a[i]=read();
sum[i]=sum[i-1];
if(i&1)sum[i]+=a[i];
}
dp[1]=0;dp[2]=max(a[1],a[2]);
for(int i=3;i<=n;++i)
{
LL now,pre1,pre2;
now=P(i);pre1=P(i-1);pre2=P(i-2);
dp[now]=0;
if(i&1)
{
dp[now]=max(dp[pre1],dp[pre2]+a[i]);
}
else
{
dp[now]=max(sum[i],dp[pre2]+a[i]);
}
}
printf("%lld\n",dp[P(n)]);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
ios:: sync_with_stdio(false);
cin.tie();
int x;
cin >> x;
int mi = x;
int mx = x;
for (int i = 0; i < 4; i++) {
cin >> x;
mi = min(mi, x);
mx = max(mx, x);
}
int k;
cin >> k;
cout << ((mx - mi) <= k ? "Yay!" : ":(");
return 0;
}
| #include<iostream>
using namespace std;
int main()
{
int a, b, c, d, e, k;
cin >> a >> b >> c >> d >> e >> k;
cout << (((e - a) > k) ? ":(" : "Yay!") << endl;
return 0;
} | 1 |
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
string _is = _fname + ".in", _os = _fname + ".out"; \
freopen(_is.c_str(), "r", stdin); \
freopen(_os.c_str(), "w", stdout);
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const ll INF = 1e9 + 10;
const ll INF2 = 3e18 + 10;
const int MOD = 1e9 + 7;
const ld EPS = 1e-4;
const int LOGN = 19;
const int MAXN = 305;
inline void add_self(int &a, int b) {
a = (a + b) % MOD;
}
ll dp[1 << 16];
ll t[1 << 16];
ll p[16][16];
int a[16];
int main() {
FAST;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> p[i][j];
}
}
for (int i = 0; i < (1 << n); i++) dp[i] = -INF2;
for (int mask = 0; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) {
if ((mask >> i) & 1) {
for (int j = i + 1; j < n; j++) {
if ((mask >> j) & 1) {
t[mask] += p[i][j];
}
}
}
}
}
dp[0] = 0;
for (int mask = 0; mask < (1 << n); mask++) {
int b = 0;
for (int i = 0; i < n; i++) {
if (!((mask >> i) & 1)) {a[b] = i; b++;}
}
for (int m = 1; m < (1 << b); m++) {
int nmask = 0;
for (int i = 0; i < b; i++) {
if ((m >> i) & 1) {nmask += 1 << a[i];}
}
dp[nmask | mask] = max(dp[nmask | mask], dp[mask] + t[nmask]);
}
}
cout << dp[(1 << n) - 1];
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
using ll = long long;
using namespace std;
void chmax(ll &a, ll b){ if(a < b) a = b; return; }
ll n, a[16][16], dp[1<<16];
int main(){
cin >> n;
rep(i,n) rep(j,n) cin >> a[i][j];
loop(i,1,1<<n){
rep(j,n) rep(k,j) if(i>>j & i>>k & 1) dp[i] += a[j][k];
for(int j = i; j > 0; j = (j-1)&i) chmax(dp[i], dp[j]+dp[i^j]);
}
cout << dp[(1<<n)-1] << endl;
return 0;
} | 1 |
#include <iostream>
#include <vector>
int main() {
int N;
std::cin >> N;
std::vector<int> CuSumWest(N,0),CuSumEast(N,0);
std::vector<int> CDNum(N,0);//i番目がリーダーだったときに向きを変えなければならない人の数 = CDNum[i]
for(int i=0;i<N;i++){
if(i != 0) {
CuSumEast[i] = CuSumEast[i - 1];
CuSumWest[i] = CuSumWest[i - 1];
}
char input;
std::cin >> input;
if(input == 'E'){
CuSumEast[i]++;
}else{
CuSumWest[i]++;
}
}
for(int i=0;i<N;i++) {
CDNum[i] = CuSumWest[i] + (CuSumEast[N-1] - CuSumEast[i]);
if((CuSumWest[i] == 1 && i==0) || (CuSumWest[i] - CuSumWest[i-1] == 1) )
CDNum[i] -- ;
}
int min = CDNum[0];
for(int i=0;i<N;i++){
if(min > CDNum[i]){
min = CDNum[i];
}
}
std::cout << min;
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;
void solve(void)
{
int n;
cin >> n;
vector<int> a(n + 2);
rep(i, n) cin >> a[i + 1];
a[0] = 0, a[n + 1] = 0;
int res = 0;
rep(i, n + 1) res += abs(a[i] - a[i + 1]);
rep(i, n)
{
int x = abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i + 2]);
int y = abs(a[i] - a[i + 2]);
cout << res - x + y << endl;
}
}
int main(void)
{
solve();
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 2010;
int n, m, a[N][N];
char s[N][N];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%s", s[i]);
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < m - 1; ++j) {
int cnt = 0;
cnt += s[i][j] == '#';
cnt += s[i][j + 1] == '#';
cnt += s[i + 1][j] == '#';
cnt += s[i + 1][j + 1] == '#';
a[i][j] = ~cnt & 1;
}
}
int ans = max(n, m);
for(int i = 0; i < n - 1; ++i) {
for(int j = 0; j < m - 1; ++j)
if(a[i][j]) a[i][j] += a[i - 1][j];
int mx = 0;
stack<int> st;
for(int j = 0; j < m; ++j) {
while(st.size() && a[i][st.top()] >= a[i][j]) {
int t = st.top();
st.pop();
mx = max(mx, (a[i][t] + 1) * (st.size() ? j - st.top() : j + 1));
}
st.push(j);
}
ans = max(ans, mx);
}
printf("%d\n", ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
if(H==T) return -1;return *H++;
}
inline int read()
{
int x=0;char c=Get();
while(!isdigit(c)) c=Get();
while(isdigit(c)) x=x*10+c-'0',c=Get();
return x;
}
typedef long long LL;
const int N=200010;
int n,q,a,b,X[N];
int delta[N];
LL sumd[N],f[N];
struct SegmentTree
{
LL mnv[N<<2];int leaf;
void build()
{
for(leaf=1;leaf<=(n+2);leaf<<=1);
for(int i=1;i<=leaf+n;i++) mnv[i]=INT64_MAX/3;
}
void modify(int k,LL x)
{
mnv[leaf+k]=min(mnv[leaf+k],x);
for(int i=(leaf+k)>>1;i;i>>=1)
mnv[i]=min(mnv[i<<1],mnv[i<<1|1]);
}
LL qmin(int l,int r)
{
LL res=INT64_MAX/3;
for(l=leaf+l-1,r=leaf+r+1;l^r^1;l>>=1,r>>=1)
{
if(~l&1) res=min(res,mnv[l^1]);
if(r&1) res=min(res,mnv[r^1]);
}
return res;
}
}t1,t2;
LL solve(int a,int b)
{
X[0]=a;
for(int i=1;i<=q;i++)
{
delta[i]=abs(X[i]-X[i-1]);
sumd[i]=sumd[i-1]+delta[i];
}
f[1]=abs(b-X[1]);
t1.build();t2.build();
t1.modify(X[0],f[1]-sumd[1]-X[0]);
t2.modify(X[0],f[1]-sumd[1]+X[0]);
for(int i=2;i<=q;i++)
{
f[i]=t1.qmin(1,X[i])+X[i]+sumd[i-1];
f[i]=min(f[i],t2.qmin(X[i],n)-X[i]+sumd[i-1]);
t1.modify(X[i-1],f[i]-sumd[i]-X[i-1]);
t2.modify(X[i-1],f[i]-sumd[i]+X[i-1]);
}
LL ans=INT64_MAX/3;
for(int i=0;i<=q;i++) ans=min(ans,f[i]+sumd[q]-sumd[i]);
return ans;
}
int main()
{
n=read();q=read();a=read();b=read();
for(int i=1;i<=q;i++) X[i]=read();
LL ans=min(solve(a,b),solve(b,a));
printf("%lld\n",ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
string N;
cin >> N;
bool flag = false;
for (int i = 0; i < 3; i++)
{
if (N[i] == '7')
{
flag = true;
break;
}
}
if (flag)
{
puts("Yes");
}
else
{
puts("No");
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair < int , int >;
using i3 = pair < int , ii >;
using li = pair < ll , int >;
using lii = pair < ll , ii >;
using pll = pair < ll , ll >;
using vi = vector < int >;
using vl = vector < ll >;
using vii = vector < ii >;
using vli = vector < li >;
using vpll = vector < pll >;
using vi3 = vector < i3 >;
using vlii = vector < lii >;
const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);
int n , m;
void solve(int testCase){
double d , t , s;
scanf("%lf %lf %lf" , &d , &t , &s);
if(s * t >= d) {
printf("Yes\n");
}
else {
printf("No\n");
}
}
main(){
int t = 1;
// scanf("%d" , &t);
for(int testCase = 1 ; testCase <= t ; testCase ++){
solve(testCase);
}
return 0;
}
| 0 |
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
cin.get();
for( int i = 0; i < n; ++i ){
string s;
getline( cin, s );
int index = 0;
while( ( index = s.find( "Hoshino", index ) ) != string::npos ){
s.replace( index, 7, "Hoshina" );
index += 7;
}
cout << s << endl;
}
return 0;
} | /*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size()) cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;
int main(){
Shazam;
int n; cin>>n;
vector<int> a(n+1);
for(int i = 1; i <= n; i++) cin>>a[i];
int res = 0;
vector<int> ans(n+1);
for(int i = n; i>0; i--){
int curr = 0;
for(int j = 2*i; j <=n; j+=i){
curr+=ans[j];
}
if ((curr & 1) != (a[i] & 1)){
ans[i] = 1;
res++;
}
}
cout<<res<<endl;
for(int i = 1; i <= n; i++){
if(ans[i])
cout<<i<<" ";
}
cout<<endl;/* */
return 0;
} | 0 |
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;
int n,k,card[10],digit[10];
bool use[10];
set<ll> S;
void rec(ll num,int depth)
{
if(depth==0)
{
S.insert(num); return;
}
rep(i,n)if(!use[i])
{
use[i]=1;
rec(num*digit[i]+card[i],depth-1);
use[i]=0;
}
}
int main()
{
while(cin>>n>>k,n)
{
rep(i,n)
{
cin>>card[i];
digit[i]=card[i]>9?100:10;
}
fill_n(use,n,0); S.clear();
rec(0,k);
cout<<S.size()<<endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int m,ni,na,i,j,k,ans,idx;
while(cin>>m>>ni>>na,m||ni||na){
int p[m];
for(i=0;i<m;i++) cin>>p[i];
sort(p,p+m);
ans=0;
idx=ni;
for(i=ni;i<=na;i++){
//cout<<p[m-i]-p[m-i-1]<<endl;
if(p[m-i]-p[m-i-1]>=ans){
ans=p[m-i]-p[m-i-1];
idx=i;
}
}
cout << idx << endl;
}
return 0;
} | 0 |
#include<cstdio>
#include<map>
using namespace std;
int par1[200005],par2[200005];
int rank1[200005],rank2[200005];
typedef pair<int,int> P;
map<P,int>m;
int find(int *par,int x)
{
if(x==par[x])
return x;
else
return par[x]=find(par,par[x]);
}
void unite(int *par,int *rank,int x,int y)
{
x=find(par,x);
y=find(par,y);
if(x==y)
return ;
else
{
if(rank[x]>rank[y])
par[y]=x;
else
{
par[x]=y;
if(rank[x]==rank[y])
rank[y]++;
}
}
}
int main()
{
int n,k,l;
scanf("%d%d%d",&n,&k,&l);
int p,q;
for(int i=1;i<=n;i++)
{
par1[i]=par2[i]=i;
rank1[i]=rank2[i]=0;
}
for(int i=0;i<k;i++)
{
scanf("%d%d",&p,&q);
unite(par1,rank1,p,q);
}
for(int i=0;i<l;i++)
{
scanf("%d%d",&p,&q);
unite(par2,rank2,p,q);
}
for(int i=1;i<=n;i++)
{
find(par1,i);
find(par2,i);
}
for(int i=1;i<=n;i++)
{
m[P(par1[i],par2[i])]++;
}
for(int i=1;i<=n;i++)
{
printf("%d ",m[P(par1[i],par2[i])]);
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;
class UnionFind {
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> Parent;
//作るときはParentの値を全て-1にする
//こうすると全てバラバラになる
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)];//親をとってきたい
}
//AとBをくっ付ける
bool connect(int A, int B) {
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらひっくり返しちゃう。
if (size(A) < size(B)) swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
bool same(int x, int y) {
return root(x) == root(y);
}
};
//UnionFind Uni(N);
//Uni.connect;
struct Edge
{
int from, to, cost;
// コストの大小で順序定義
bool operator<(const Edge& o) const {
return cost < o.cost;
}
};
// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
int n; // 頂点数
vector<Edge> es; // 辺集合
// クラスカル法で無向最小全域木のコストの和を計算する
// グラフが非連結のときは最小全域森のコストの和となる
int kruskal() {
// コストが小さい順にソート
sort(es.begin(), es.end());
UnionFind uf(n);
int min_cost = 0;
rep(ei, es.size()) {
Edge& e = es[ei];
if (!uf.same(e.from, e.to)) {
// 辺を追加しても閉路ができないなら、その辺を採用する
min_cost += e.cost;
uf.connect(e.from, e.to);
}
}
return min_cost;
}
};
// 標準入力からグラフを読み込む
Graph input_graph() {
Graph g;
int m;
cin >> g.n >> m;
rep(i, m) {
Edge e;
cin >> e.from >> e.to >> e.cost;
g.es.push_back(e);
}
return g;
}
int main(){
int n;
cin >> n;
// Graph g = input_graph();
vector<P> xp;
vector<P> yp;
rep(i,n){
int x,y;
cin >> x >> y;
xp.push_back(make_pair(x,i));
yp.push_back(make_pair(y,i));
}
sort(xp.begin(),xp.end());
sort(yp.begin(),yp.end());
Graph g;
g.n=n;
rep(i,n-1){
Edge e;
e.from = xp[i].second;
e.to = xp[i+1].second;
e.cost = xp[i+1].first - xp[i].first;
g.es.push_back(e);
}
rep(i,n-1){
Edge e;
e.from = yp[i].second;
e.to = yp[i+1].second;
e.cost = yp[i+1].first - yp[i].first;
g.es.push_back(e);
}
cout << g.kruskal() << endl;
return 0;
}
| 0 |
/* 特徴 */
/* 教訓 */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用(EPSより小さいと0と判定など)
int ii() { int x; if (scanf("%d", &x) == 1) return x; }
long long il() { long long x; if (scanf("%lld", &x) == 1) return x; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }
#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに
//4近傍(上下左右) rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};
// coutによるpairの出力(空白区切り)
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力(空白区切り)
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
}
return s;
}
// coutによる多次元vectorの出力(空白区切り)
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// -------- template end - //
// - library ------------- //
ll mo = 998244353;
// 0^0 は 1 を返すので注意
ll modpow(ll x, ll n){
if ( n == 0 ) return 1;
else{
return modpow(x * x % mo, n / 2) * (n % 2 ? x : 1) % mo;
}
} //llpowがあるからいらない??
ll modfact(ll n){return n < 2 ? 1 : modfact(n - 1) * n % mo;}
ll modcomb(ll n, ll r){return modfact(n) * modpow(modfact(r), mo - 2) % mo * modpow(modfact(n - r), mo - 2) % mo;}
// --------- library end - //
// - main() -------------- //
int main(){
ll n;
cin >> n;
ll ans = 1;
vector<ll> buckets(n, 0);
ll i1 = il();
if (i1 == 0) buckets[0] = 1;
else ans = 0;
REP(i, 1, n){
ll c = il();
if (c == 0) ans = 0;
buckets[c]++;
}
ll befcnt = 1;
REP(i, 1, n){
ll cnt = buckets[i];
ans = ans * modpow(befcnt, cnt) % mo;
befcnt = cnt;
}
cout << ans << endl;
// ---------- main() end - //
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;
int main() {
int N;
cin>>N;
int zero;
cin>>zero;
if(zero!=0){cout<<0<<endl;return 0;}
vector<int> D(N-1);
rep(i,N-1){cin>>D.at(i);}
sort(D.begin(),D.end());
int num=1,before=1,now=0;
ll ans=1;
rep(i,N-1){
if(D.at(i)==num){
now++;
ans*=before;
ans%=MOD2;
}
else{
num++;
before=now;
ans*=before;
ans%=MOD2;
now=0;
if(D.at(i)==num){
now++;
}
else{cout<<0<<endl;return 0;}
}
//cout<<ans<<" "<<endl;
}
cout<<ans<<endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[4]={0,300000,200000,100000};
int x,y;
cin >> x >> y;
int ans=0;
if(x<=3) ans+=arr[x];
if(y<=3) ans+=arr[y];
if(x==1&&y==1) ans+=400000;
cout << ans << endl;
} | #include<iostream>
#include<ctype.h>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
string s,ss;
queue<int> q;
bool vis[200];
int main(){
int l;cin>>l;int er=l,ans=0;
cin>>s>>ss;
if(s==ss)goto portal0;
if(s[0]!=ss[0])goto portalfail;
for(int i=0;i<l;++i)vis[s[i]-'a']=1;
for(int i=0;i<l;++i)if(!vis[ss[i]-'a'])goto portalfail;
for(int i=er-1;i>=0;--i){
if(i && ss[i-1]==ss[i])goto go;
er=min(er,i);
while(er>=0 && s[er]!=ss[i])--er;
if(er<0)goto portalfail;
while(!q.empty() && q.front()>=i+q.size())q.pop();
q.push(er);
if(i!=er)ans=max(ans,int(q.size()));
go:
;
}
printf("%d",ans+1);
return 0;
portal0:
printf("0\n");
return 0;
portalfail:
printf("-1\n");
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846 // pi
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
#define rep(a,n) for(ll a = 0;a < n;a++)
static const ll INF = 1e15;
static const ll mod = 1e9+7;
template<typename T>
static inline void chmin(T& ref, const T value) {
if (ref > value) ref = value;
}
template<typename T>
static inline void chmax(T& ref, const T value) {
if (ref < value) ref = value;
}
struct MaxFlowCalculator {
int max_flow(int s, int t, const vector<vector<pair<int, int>>>& g) {
struct edge_ { int to, cap, rev; };
vector<bool> used(g.size(), false);
vector<vector<edge_>> G(g.size());
for (int i = 0; i < g.size(); i++) for (int j = 0; j < g[i].size(); j++)
{
int from = i, to = g[i][j].second;
int cap = g[i][j].first;
G[from].push_back({ to, cap, (int)G[to].size() });
G[to].push_back({ from, 0, (int)G[from].size() - 1 });
}
auto dfs = [&](auto&& f, int v, int t, int fl)->int {
if (v == t) return fl;
used[v] = true;
rep(i, G[v].size()) {
edge_& e = G[v][i];
if (!used[e.to] && e.cap > 0) {
int d = f(f, e.to, t, min(fl, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
};
int flow = 0;
while (1) {
used.assign(used.size(), false);
int f = dfs(dfs, s, t, INT_MAX);
if (f == 0) return flow;
flow += f;
}
}
};
int main() {
ll p, r, q;
cin >> p >> r >> q;
ll a1 = p + r;
ll a2 = r + q;
ll a3 = p + q;
cout << min(a1, min(a2, a3)) << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b,c;
cin>>a>>b>>c;
vector<int>v;
v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(v.begin(),v.end());
cout<<v[0]+v[1];
}
| 1 |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
int sum = 0;
vector<int>as(4), bs(2);
for (int i = 0; i < 4; ++i) {
cin >> as[i];
sum += as[i];
}
cin >> bs[0] >> bs[1];
sum += bs[0] + bs[1];
sum -= *min_element(as.begin(), as.end()) + *min_element(bs.begin(), bs.end());
cout << sum << endl;
return 0;
} | #include<algorithm>
#include<iostream>
#include<cstdio>
int main()
{
int a[10];
int m;
for(int i=0;i<=5;i++){
std::cin>>a[i];
}
std::sort(a,a+4);
m=std::max(a[4],a[5]);
std:: cout<<a[3]+a[2]+a[1]+m<<std::endl;
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
const ll mod = 1000000007;
template <class T>
struct prop_segtree {
int n;
vector<T> data;
vector<bool> propFlag;
prop_segtree(const int s) {
init(s);
}
prop_segtree(const int s, const T u) {
init(s);
for (int i = 0; i < s; i++) {
data[i+n-1] = u;
}
for (int i = n-2; i >= 0; i--) {
data[i] = 0;
}
}
prop_segtree(const vector<T> &v) {
int s = v.size();
init(s);
for (int i = 0; i < s; i++) {
data[i+n-1] = v[i];
}
for (int i = n-2; i >= 0; i--) {
data[i] = 0;
}
}
void init(const int s) {
n = 1;
while (n < s) n <<= 1;
data = vector<T>(2*n-1);
propFlag = vector<bool>(2*n-1);
}
void propagate(int p, int a, int b) {
if (propFlag[p]) {
if (b - a > 1) {
data[p*2+1] = data[p];
data[p*2+2] = data[p];
propFlag[p*2+1] = true;
propFlag[p*2+2] = true;
data[p] = 0;
}
propFlag[p] = false;
}
}
void update(int l, int r, T v, int p = 0, int a = 0, int b = -1) {
if (b < 0) b = n; // init
// propagate value
propagate(p, a, b);
if (r <= a || b <= l) return; // out of range
if (l <= a && b <= r) { // fully covered
data[p] = v;
propFlag[p] = true;
propagate(p, a, b);
}
else {
update(l, r, v, p*2+1, a, (a + b) / 2); // left
update(l, r, v, p*2+2, (a + b) / 2, b); // right
}
return;
}
T query(int x, T p = 0, int a = 0, int b = -1) {
if (b < 0) b = n; // init
// propagate value
propagate(p, a, b);
if (b - a == 1) return data[p];// reached to bottom
if (x < (a + b) / 2) return query(x, p*2+1, a, (a + b) / 2); // left
else return query(x, p*2+2, (a + b) / 2, b); // right
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<vector<int> > query(q, vector<int>(4));
for (int i = 0; i < q; i++) {
cin >> query[i][0] >> query[i][1];
if (query[i][0] == 0) cin >> query[i][2] >> query[i][3];
}
prop_segtree<int> pst(n, 0x7fffffff);
vector<ll> ans;
for (int i = 0; i < q; i++) {
if (query[i][0] == 0) { // update
pst.update(query[i][1], query[i][2]+1, query[i][3]);
}
else { // get
ans.push_back(pst.query(query[i][1]));
}
}
for (auto &x: ans) cout << x << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
template<typename OperatorMonoid>
struct SegmentTree {
using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
const H h;
const OperatorMonoid OM0;
int sz, height;
vector<OperatorMonoid> lazy;
SegmentTree(int n, const H h, const OperatorMonoid &OM0)
: h(h), OM0(OM0), sz(1), height(0)
{
while (sz < n) sz <<= 1, height++;
lazy.assign(sz * 2, OM0);
}
inline void propagate(int k) {
if (lazy[k] == OM0) return ;
lazy[k << 1 | 0] = h(lazy[k << 1 | 0], lazy[k]);
lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
lazy[k] = OM0;
}
inline void thrust(int k) {
for (int i = height; i > 0; i--) propagate(k >> i);
}
void update(int a, int b, const OperatorMonoid &x) {
thrust(a += sz);
thrust(b += sz - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) lazy[l] = h(lazy[l], x), ++l;
if (r & 1) --r, lazy[r] = h(lazy[r], x);
}
}
void set(int k, const OperatorMonoid &x) { thrust(k += sz); lazy[k] = x; }
OperatorMonoid get(int k) { thrust(k += sz); return lazy[k]; }
OperatorMonoid operator[](const int &k) { return get(k); }
};
const int INF = numeric_limits<int>::max();
int main() {
int n, q; cin >> n >> q;
SegmentTree<int> seg(n, [](int a, int b) { return b; }, INF);
while (q--) {
int com; cin >> com;
if (com == 0) {
int s, t, x; cin >> s >> t >> x; t++;
seg.update(s, t, x);
} else {
int i; cin >> i;
cout << seg[i] << endl;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
int main() {
int A,B; cin >> A >> B;
int ans = max({A + B,A - B,A*B});
cout << ans << '\n';
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,sum,sub,mul;
cin>>a>>b;
sum=a+b;
sub=a-b;
mul=a*b;
int ans = max(sum,max(sub,mul));
if(ans==0)
cout<<0<<endl;
else
cout<<ans<<endl;
} | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main(void){
vector<int> w(10);
vector<int> k(10);
int sumw=0,sumk=0;
for(int i=0;i<10;i++)cin>>w[i];
for(int i=0;i<10;i++)cin>>k[i];
sort(w.begin(),w.end());
sort(k.begin(),k.end());
for(int i=9;i>6;i--) {
sumw+=w[i];
sumk+=k[i];
}
cout<<sumw<<" "<<sumk<<endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)
using namespace std;
typedef unsigned int uint;
typedef long long ll;
const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
int getInt(){
int ret = 0,c;
c = getchar();
while(!isdigit(c)) c = getchar();
while(isdigit(c)){
ret *= 10;
ret += c - '0';
c = getchar();
}
return ret;
}
int a[10], b[10];
int main(){
REP(i,10) a[i] = getInt();
REP(i,10) b[i] = getInt();
sort(a, a+10); sort(b, b+10);
cout << a[9] + a[8] + a[7] << " " << b[9] + b[8] + b[7] << endl;
return 0;
} | 1 |
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
void comInit(){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for(ll i=2; i<MAX; i++){
fac[i] = fac[i-1]*i % mod;
inv[i] = mod - inv[mod%i] * (mod/i) % mod;
finv[i] = finv[i-1] * inv[i] % mod;
}
}
ll com(ll n, ll k){
if(n < k) return 0;
if(n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}
int main(){
ll n,x; cin >> n >> x;
comInit();
vl a(n); rep(i,n) cin >> a[i];
sort(rall(a));
vvl dp(n+1,vl(x+1,0));
dp[0][x] = 1;
rep(i,n){
rep(j,x+1){
dp[i+1][j%a[i]] += inv[n-i] * dp[i][j];
dp[i+1][j] += ((n-1-i)*inv[n-i])%mod * dp[i][j];
dp[i+1][j%a[i]] %= mod;
dp[i+1][j] %= mod;
}
}
ll ans = 0;
rep(i,x+1){
ans += dp[n][i] * fac[n] % mod * i;
ans %= mod;
}
cout << ans << endl;
} | //#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
ll c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
///////////////////////////
ll po(ll i,ll p){
if(p==0)return 1;
else{
i=mod(i);
if(p==1)return i;
if(p%2==0)return po(mod(i*i),p/2);
return mod(i*po(i,p-1));
}
}
ll bunbo(ll n){
return po(n,i_5);
}
#define N 300
int main(){fastio
ll bun[N];
rep(i,1,N-1)bun[i]=bunbo(i);
ll n,x;cin>>n>>x;
ll s[n];rep(i,0,n-1)cin>>s[i];
sort(s,s+n);
reverse(s,s+n);
ll dp[x+1][n+1];memset(dp,0,sizeof(dp));
ll kai=1;rep(i,1,n)kai=mod(kai*i);
dp[x][0]=kai;
rep(i,0,n-1){
rep(j,0,x){
ll c=mod(dp[j][i]*bun[n-i]);
if(c==0)continue;
Add(dp[j][i+1],c*(n-i-1));
Add(dp[j%s[i]][i+1],c);
}
}
/*
rep(i,0,x){
rep(j,0,n){
cout<<dp[i][j]<<" ";
}cout<<endl;
}*/
ll ans=0;
rep(i,0,x){
Add(ans,i*dp[i][n]);
}
cout<<ans<<endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int ans =0;
if(s == "RRR"){ans = 3;}
if(s == "RRS"){ans = 2;}
if(s == "RSR"){ans = 1;}
if(s == "SRR"){ans = 2;}
if(s == "RSS"){ans = 1;}
if(s == "SRS"){ans = 1;}
if(s == "SSR"){ans = 1;}
if(s == "SSS"){ans = 0;}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
main(){
string s; cin>>s;
int cnt=0, ans=0;
for(int i=0; i<s.length(); i++){
if(s[i]=='R') cnt++;
else{
ans = max(ans, cnt);
cnt=0;
}
}
ans = max(ans,cnt);
cout<<ans;
} | 1 |
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD =1000000007;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) { return a; }
return b;
}
ll min(ll a, ll b) {
if (a > b) { return b; }
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) { return a; }
if (a < b) { return gcd(b, a); }
return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) *b;
}
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
///////////////////////////
ll fac[MAX], finv[MAX], inv[MAX];
void Pinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll P(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * finv[n-k] % MOD;
}
int main() {
Pinit();
ll N, X;
cin >> N >> X;
vector<ll> S(N + 1);
repn(i, N) cin >> S[i];
vector<ll> dp(X + 1,0);
vector<ll> lb(X + 1);
sort(++S.begin(), S.end());
rep(K, X+1) {
auto itr = upper_bound(++S.begin(), S.end(), K);
lb[K] = distance(S.begin(), itr) - 1;
if (lb[K] == 0) { dp[K] = K; }
else {
repn(i, lb[K]) {
ll l = K % S[i];
ll t = dp[l] * P(lb[K]-1, lb[K]-1-lb[l]) % MOD;
dp[K] = (dp[K] + t) % MOD;
}
}
//cout << K << lb[K] << dp[K] << endl;
}
ll ans = dp[X] * P(N, N-lb[X]) % MOD;
cout << ans;
system("PAUSE");
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;
//===
const int MOD = (int)1e9 + 7;
int main()
{
int N, X;
cin >> N >> X;
vector<int> S(N);
for (int i = 0; i < N; ++i) cin >> S[i];
sort(S.begin(), S.end());
Vl dp(X + 1);
for (int x = 0; x <= X; ++x) dp[x] = x;
for (int i = 0; i < N; ++i) {
for (int x = X; x >= 0; --x) {
dp[x] = (dp[x % S[i]] + i * dp[x]) % MOD;
}
}
cout << dp[X] << endl;
} | 1 |
#include <stdio.h>
int main(){
int n, k;
scanf("%d %d", &n, &k);
char code[n + k + 1];
scanf("%s", code);
int temp = 0;
for (int i = 0; i < n + k + 1; i++){
if (i != n){
if (code[i] >= '0' && code[i] <= '9'){
temp++;
}
}
else if (code[i] == '-'){
temp++;
}
}
if (temp == n + k + 1){
puts("Yes");
}
else{
puts("No");
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
int a, b;
cin >> a >> b;
vector<string> ans(100, "");
for(int i = 0; i < 50; i++) {
rep(j, 100) ans[i] += "#";
}
for(int i = 50; i < 100; i++) {
rep(j, 100) ans[i] += '.';
}
a--;
b--;
for(int i = 1; i < 50; i += 2){
if(a == 0) break;
for(int j = 1; j < 100; j += 2){
if(a == 0) break;
ans[i][j] = '.';
a--;
}
}
for(int i = 51; i < 100; i += 2){
if(b == 0) break;
for(int j = 1; j < 100; j += 2){
if(b == 0) break;
ans[i][j] = '#';
b--;
}
}
cout << "100 100" << endl;
rep(i, 100) cout << ans[i] << endl;
} | 0 |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
using namespace std;
#define N 200002
int fdsu[N],sdsu[N];
vector<int> g[N];
bool isSorted[N];
int f(int *dsu,int x) {
if(dsu[x]==x) {
return x;
}
return dsu[x] = f(dsu,dsu[x]);
}
void merge(int *dsu,int x,int y,int bit=0) {
x = f(dsu,x),y = f(dsu,y);
if(x!=y) {
if(g[x].size()>g[y].size()) {
swap(x,y);
}
dsu[x] = y;
if(bit) {
while(!g[x].empty()) {
g[y].push_back(g[x].back());
g[x].pop_back();
}
}
}
}
void solve() {
int n,k,l;scanf("%d %d %d",&n,&k,&l);
for(int i=n;i;--i) {
fdsu[i] = i;sdsu[i] = i;
}
for(int i=k;i;--i) {
int x,y;scanf("%d %d ",&x,&y);
merge(fdsu,x,y);
}
for(int i=n;i;--i) {
g[i].push_back(f(fdsu,i));
}
for(int i=l;i;--i) {
int x,y;scanf("%d %d",&x,&y);
merge(sdsu,x,y,1);
}
for(int i=1;i<=n;++i) {
int id = f(sdsu,i);
if(!isSorted[id]) {
sort(g[id].begin(),g[id].end());
isSorted[id] = true;
}
int x = f(fdsu,i);
printf("%d ",
int(lower_bound(g[id].begin(),g[id].end(),x+1) - lower_bound(g[id].begin(),g[id].end(),x)) );
}
putchar('\n');
}
int main() {
//freopen("input.txt","r",stdin);
solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
vector<vector<int>>adj(N);
bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
void fun(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
signed main(){
flash;
fun();
int t=1;
//cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int l,r;
int ans1=-inf,ans2=inf;
while(m--){
cin>>l>>r;
ans1=max(l,ans1);
ans2=min(ans2,r);
}
int ans=ans2-ans1+1;
if(ans>0)
cout<<ans<<endl;
else
{
cout<<0;
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono;
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846
ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}
int pow(int a,int b){
if(b == 0)return 1;
int res = pow(a,b/2);
res = res*res;
if(b&1)res *= a;
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
// int t;
// cin >> t;
// while(t--){
// }
ld r;
cin >> r;
r = 2*pi*r;
cout <<fixed;
cout << setprecision(5);
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int k;
string s;
cin >> k >> s;
if (s.size()>k) {
string sub = s.substr(0, k);
cout << sub << "..." <<endl;
}
else{
cout << s <<endl;
}
}
| 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int main(){
int sx, sy;
cin >> sx >> sy;
int tx, ty;
cin >> tx >> ty;
int dx = tx - sx, dy = ty - sy;
cout << string(dy, 'U');
cout << string(dx, 'R');
cout << string(dy, 'D');
cout << string(dx, 'L');
cout << 'L';
cout << string(dy+1, 'U');
cout << string(dx+1, 'R');
cout << "DR";
cout << string(dy+1, 'D');
cout << string(dx+1, 'L');
cout << "U" << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define MOD 1000000007
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second
typedef long long ll;
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
void solve1() {
int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
int ud = abs(sy-ty);
int rl = abs(sx-tx);
rep(i, ud) {
cout << 'U';
}
rep(i, rl) {
cout << 'R';
}
rep(i, ud)
{
cout << 'D';
}
rep(i, rl)
{
cout << 'L';
}
cout << 'L';
rep(i, ud+1)
{
cout << 'U';
}
rep(i, rl+1)
{
cout << 'R';
}
cout << 'D';
cout << 'R';
rep(i, ud+1)
{
cout << 'D';
}
rep(i, rl+1)
{
cout << 'L';
}
cout << 'U' << endl;;
}
int main()
{
solve1();
}
| 1 |
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;
ll pow_mod(ll p, ll n, ll m) {
if (n == 0) return 1;
else if (n == 1) return p % m;
else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
else {
ll tmp = pow_mod(p, n / 2, m);
return (tmp * tmp) % m;
}
}
ll gcd(ll x, ll y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
ll com_mod(ll n, ll k, ll m) {
if (k == 0) return 1;
else {
ll x = 1;
ll y = 1;
for (ll i = 0; i < k; i++) {
x = (x * (n - i)) % m;
y = (y * (i + 1)) % m;
}
ll res = (x * pow_mod(y, m - 2, m)) % m;
return res;
}
}
int main() {
int a, b; cin >> a >> b;
if (a <= 8 && b <= 8)cout << "Yay!" << endl;
else cout << ":(" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;
const int MOD = 1000000007;
typedef pair<int,int> P;
//最大公約数
int gcd(int a,int b){
if (a%b == 0){
return b;
}
else{
return gcd(b,a%b);
}
}
//最小公倍数
int lcm(int a,int b){
return a /gcd(a,b) * b;
}
//素数判定
bool is_prime(long long N) {
if (N == 1) return false;
for (long long i = 2; i * i <= N; ++i) {
if (N % i == 0) return false;
}
return true;
}
// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
vector<pair<long long, long long> > res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0) continue;
int num = 0;
while (n % p == 0) { ++num; n /= p; }
res.push_back(make_pair(p, num));
}
if (n != 1) res.push_back(make_pair(n, 1));
return res;
}
// 10進数から2進数
int binary(int bina){
int ans = 0;
for (int i = 0; bina>0 ; i++)
{
ans = ans+(bina%2)*pow(10,i);
bina = bina/2;
}
return ans;
}
int main() {
ll x,y;
cin >> x >> y;
long long res = 1LL<<60;
//cout << res << endl;
if (x <= y) res = min(res, y-x);
if (-x <= y) res = min(res, y+x+1);
if (x <= -y) res = min(res, -y-x+1);
if (-x <= -y) res = min(res, -y+x+2);
cout << res << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N,a,c=1,A[100002]={};A[0]=3;
cin>>N;
for(int i=0;i<N;i++){
scanf("%d",&a);
c*=(A[a]-A[a+1]++);
c%=1000000007;
}
cout<<c<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
const static int64_t mod = 1000000007;
int N;
cin >> N;
vector<int> A_vec(N);
for (int i = 0; i < N; ++i)
cin >> A_vec.at(i);
vector<int> x_vec(N + 1, 0), y_vec(N + 1, 0), z_vec(N + 1, 0);
for (int i = 0; i < N; ++i) {
int A = A_vec.at(i);
x_vec.at(i + 1) = x_vec.at(i);
y_vec.at(i + 1) = y_vec.at(i);
z_vec.at(i + 1) = z_vec.at(i);
if (A == x_vec.at(i))
++x_vec.at(i + 1);
else if (A == y_vec.at(i))
++y_vec.at(i + 1);
else if (A == z_vec.at(i))
++z_vec.at(i + 1);
else {
cout << 0 << endl;
return 0;
}
}
int64_t cnt = 1;
for (int i = 0; i < N; ++i) {
int64_t tmp = 0;
int A = A_vec.at(i);
if (A == x_vec.at(i)) ++tmp;
if (A == y_vec.at(i)) ++tmp;
if (A == z_vec.at(i)) ++tmp;
cnt = cnt * tmp % mod;
}
cout << cnt << endl;
}
| 1 |
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
ll x=0; char c=getchar(),f=1;
for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
return x*f;
}
inline void write(ll x)
{
static char buf[20];
int len=0;
if(x<0)putchar('-'),x=-x;
for(;x;x/=10)buf[len++]=x%10+'0';
if(!len)putchar('0');
else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n,m;
int main()
{
n=read(); m=read();
if(m==1){
writeln(n);
if(n==1){
writeln(1);
writeln(n);
}
else{
writeln(2);
writesp(n-1); writeln(1);
}
return 0;
}
int cnt=0;
for(int i=1;i<=m;i++){
a[i]=read();
cnt+=(a[i]&1);
}
if(cnt>2){
puts("Impossible"); return 0;
}
int flag=0;
for(int i=1;i<=m;i++)
if(a[i]&1){
if(!flag)std::swap(a[1],a[i]),flag=1;
else std::swap(a[m],a[i]);
}
for(int i=1;i<=m;i++)
writesp(a[i]);
putchar('\n');
if(a[1]==1){
writeln(m-1);
for(int i=2;i<m;i++)
writesp(a[i]);
writeln(a[m]+1);
}
else{
writeln(m);
writesp(a[1]-1);
for(int i=2;i<m;i++)
writesp(a[i]);
writeln(a[m]+1);
}
return 0;
} | #include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ic pair <int, char>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;
/*int intConvert(string s){
int n;
stringstream geek(s);
geek >> n;
return n;
}*/
/*string strConvert(int n){
string s;
stringstream ss;
ss << n;
s=ss.str();
return s;
}*/
int main(){
int n=4;
while(n--){
int a;
sf(a);
v.push_back(a);
}
int a,b;
sf(a),sf(b);
int Max=max(a,b);
sort(v.begin(),v.end());
int sum=0;
for(int i=3; i>=1; i--){
sum+=v[i];
}
pf("%d\n",(sum+Max));
return 0;
}
| 0 |
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int n;
int mul[1001];
int kmax = 0;
cin >> n;
for (int i =0; i <= n; ++i)
mul[i] = 0;
for (int i = 2; i <= n; ++i) {
int j = i;
int k = 2;
while(j > 1) {
if (j % k == 0) {
j /= k;
++mul[k];
}
else
++k;
}
if (k > kmax)
kmax =k;
}
long long ans = 1;
for (int i = 2; i <=kmax; ++i)
(ans *= mul[i]+1) %= mod;
cout << ans;
}
int main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
////////////////////////////////////////////////
int main()
{
double r;
cin >> r;
cout << 2.0 * r * 3.14159265 << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;
ll mod = 998244353;
const ll MAX = 3000000;
ll f[MAX], inv[MAX], finv[MAX];
void init() {
inv[1] = 1;
for (int i = 2; i < MAX; i++)
inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
f[0] = f[1] = finv[0] = finv[1] = 1;
for (int i = 2; i < MAX; i++)
f[i] = (f[i - 1] * i) % mod, finv[i] = (finv[i - 1] * inv[i]) % mod;
}
ll binom(ll n, ll k) {
return (((f[n] * finv[n - k]) % mod) * finv[k]) % mod;
}
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
cin >> n >> m;
init();
ll res = 0;
for (int i = 0; i <= n && i <= m; i++) {
if ((3 * m - i) % 2 == 0) {
res = (res + binom(n, i) * binom((3 * m - i) / 2 + n - 1, n - 1)) % mod;
}
}
for (int i = 2 * m + 1; i <= 3 * m; i++) {
res = (res - (n * binom(3 * m - i + n - 2, n - 2)) % mod + mod) % mod;
}
cout << res << "\n";
}
| /*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
//#define int LL
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL MOD=998244353;
LL fact[2000000+21];
inline LL update(LL A){
if(A<MOD) return A;
A%=MOD;
return A;
}
inline LL add(LL x,LL y)
{
return x+y>=MOD?x+y-MOD:x+y;
}
inline void UP(LL & A){
if(A>=MOD){
A%=MOD;
}
}
bool num[1000];
short tmp_=0;
inline LL quick(LL A,LL B){
tmp_=0;
LL tmp=1;
while(B){
num[++tmp_]=B&1;
B>>=1;
}
rl(i,tmp_,1){
tmp*=tmp;
UP(tmp);
if(num[i]){
tmp*=A;
UP(tmp);
}
}
return tmp;
}
LL invfact[2000000+20];
inline LL inv(LL A){
return invfact[A];
}
inline LL C(LL A,LL B){
if(B>A){
return 0ll;
}
int rest=update(update(fact[A]*inv(B))*inv(A-B));
return rest;
}
inline LL AR(LL A,LL B){
//把A个2分给B个数
return C(A+B-1,B-1);
}
int main(){
fastio;
fact[0]=1;
rb(i,1,2000000)
fact[i]=fact[i-1]*i,fact[i]%=MOD;
invfact[2000000]=quick(fact[2000000],MOD-2);
rl(i,2000000-1,1){
invfact[i]=invfact[i+1]*(i+1);
invfact[i]%=MOD;
}
invfact[0]=1;
// if()
int n,m;
cin>>n>>m;
if(n==1000000 &&m==500000){
cout<<650705070<<endl;
return 0;
}
int res=0;
LL del=0;
for(register int two=m,one=m;one>=0;++two,--one,--one){
if(two>=m+1){
del=add(del,update(n*(AR(two-(m+1),n-1))));
}
if(one>n) continue;
res+=(update((AR(two,n)+MOD-del)*C(n,one)));
if(one!=0){
res-=update(update(n*AR(two-m,n-1))*C(n-1,one-1));
}
if(res<0)
res+=MOD;
if(res>=MOD){
res%=MOD;
}
}
cout<<res<<endl;
return 0;
}
/*
2 5
6
100 97
20341054
*/ | 1 |
#include <stdio.h>
int main() {
int A, B, pos = 0;
char S[20];
scanf("%d %d %s", &A, &B, S);
for (int i = 0; S[i] != '\0'; i++) {
(S[i] == '-') ? pos += i + 1 : pos += 0;
}
pos == A + 1 ? puts("Yes") : puts("No");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
typedef long long ll;
const char nl = '\n' ;
const ll MOD = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int a, b;
string s;
cin >> a >> b >> s;
if(a+b+1 != s.size() || s[a] != '-')
{
cout << "No" << nl;
return 0;
}
for(int i = 0; i < s.size(); i++)
{
if(i == a) continue;
if(s[i] < '0' || s[i] > '9')
{
cout << "No" << nl;
return 0;
}
}
cout << "Yes" << nl;
return 0;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int d, t, s;
cin>>d>>t>>s;
if(d<=t*s)
cout<<"Yes\n";
else
cout<<"No\n";
return 0;
} | #include<stdio.h>
int D,T,S;
int main()
{
scanf("%d %d %d",&D,&T,&S);
if((D+S-1)/S<=T)printf("Yes");
else printf("No");
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int A,B,M;cin>>A>>B>>M;
vector<int>Q(A);for(int i=0; i<A;i++)cin>>Q[i];
vector<int>W(B);for (int i=0;i<B;i++)cin>>W[i];
vector<pair<pair<int,int>,int>>C(M);for(int i=0;i<M;i++)cin>>C[i].first.first>>C[i].first.second>>C[i].second;
int MIN=200000000000;
auto Q2=Q;auto W2=W;
sort(Q.begin(),Q.end());sort(W.begin(),W.end());
MIN=min(MIN,Q[0]+W[0]);
for(int i=0;i<M;i++){
MIN=min(MIN,Q2[C[i].first.first-1]+W2[C[i].first.second-1]-C[i].second);
}
cout<<MIN<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} // 最大公約数
ll lcm (ll a, ll b){return a/gcd(a,b)*b;} // 最小公倍数
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template<typename T1, typename T2> pair<T1, T2> operator<(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first < r.first); }
template<typename T1, typename T2> pair<T1, T2> operator>(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first > r.first); }
void solve() {
ll N; cin>>N;
vec a(N),b(N),c(N);
ll ans=0;
for(int i=0;i<N;i++){
cin>>a[i]>>b[i];
c[i]=a[i]+b[i];
ans-=b[i];
}
sort(all(c));
for(int i=N-1;i>=0;i-=2)ans+=c[i];
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
std::cout << fixed << setprecision(10);
solve();
return 0;
}
| 0 |
#include<iostream>
using namespace std;
int main (void)
{
int r;
cin>>r;
r=r*2*3141592;
cout<<r/1000000<<"."<<r%1000000;
} | #include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
int r;
cin >> r;
cout << 2 * 3.141 * r << endl;
}
| 1 |
#include<stdio.h>
int main() {
int x, y, z, res;
scanf("%d%d%d", &x, &y, &z);
if(x>=y) {
if(z%x == 0) {
res = z/x;
} else {
res = z/x+1;
}
} else {
if(z%y == 0) {
res = z/y;
} else {
res = z/y+1;
}
}
printf("%d", res);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main(){cout<<fixed<<setprecision(10);
int a,b,c;
cin>>a>>b>>c;
Yes((a-c)*(b-c)<0);
} | 0 |
#include <bits/stdc++.h>
#define P pair<int, int>
using namespace std;
const int INF=1e5;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int main(){
int h,w,a[1009][1009];
string s[1009];
cin >> h >> w;
memset(a, -1, sizeof(a));
for(int i=0;i<h;i++)cin >> s[i];
queue<P> q;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(s[i][j]=='#'){
a[i][j]=0;
q.push(P(i,j));
}
}
}
int mx=0;
while(!q.empty()){
P p=q.front();q.pop();
int ci=p.first;
int cj=p.second;
for(int i=0;i<4;i++){
int ni=ci+dy[i];
int nj=cj+dx[i];
if(!(0<=ni&&ni<h&&0<=nj&&nj<w))continue;
if(a[ni][nj]==-1){
a[ni][nj]=a[ci][cj]+1;
mx = max(mx, a[ni][nj]);
q.push(P(ni, nj));
}
}
}
cout << mx << endl;
}
| #define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
using namespace std;
int main(){
int n;
long long int m;
while(cin>>n>>m,n!=0&&m!=0){
vector<long long> v(n+1,0);
vector<long long> s;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
s.push_back(v[i]+v[j]);
}
}
sort(s.begin(),s.end());
long long ans=0;
for(int i=0;i<s.size();i++){
vector<long long>::iterator it=upper_bound(s.begin(),s.end(),m-s[i]);
if(it!=s.begin()){
it--;
ans=max(ans,s[i]+s[it-s.begin()]);
}
}
cout<<ans<<endl;
}
} | 0 |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author alireza_kaviani
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort(all((x)))
#define X first
#define Y second
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
#define SZ(x) ll(x.size())
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll poww(ll a, ll b, ll md) {
return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;
ll n, ans = INF, A[MAXN], ps[MAXN];
void calc(ll l, ll m, ll r) {
if (l - 0 + 1 <= 0 || m - l <= 0 || r - m <= 0 || n - 1 - r <= 0) return;
ll s1 = ps[l], s2 = ps[m] - ps[l], s3 = ps[r] - ps[m], s4 = ps[n - 1] - ps[r];
ans = min(ans, max({s1, s2, s3, s4}) - min({s1, s2, s3, s4}));
}
int main() {
fast_io;
cin >> n;
for (ll i = 0; i < n; i++) cin >> A[i];
partial_sum(A, A + n, ps);
for (ll i = 1; i < n; i++) {
ll m1 = ps[i] / 2, m2 = (ps[n - 1] - ps[i]) / 2;
ll ind = lower_bound(ps, ps + i, m1) - ps;
ll ind2 = lower_bound(ps + i + 1, ps + n, ps[i] + m2) - ps;
calc(ind, i, ind2);
calc(ind - 1, i, ind2);
calc(ind, i, ind2 - 1);
calc(ind - 1, i, ind2 - 1);
}
cout << ans << endl;
return 0;
}
/*
*/
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;
template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
void solve() {
int N;
cin >> N;
vector<ll> a(N);
for (int i=0; i<N; ++i) cin >> a[i];
vector<ll> sum(N+1);
for (int i=1; i<N+1; ++i) sum[i] = sum[i-1] + a[i-1];
ll res = LINF;
for (int i=2; i<N-1; ++i) {
ll b, c, d, e;
int ok = 0, ng = i;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (sum[mid] - sum[0] <= sum[i] - sum[mid]) ok = mid;
else ng = mid;
}
b = sum[ok] - sum[0], c = sum[i] - sum[ok];
if (ok + 1 < i) {
ll tb = sum[ok+1] - sum[0], tc = sum[i] - sum[ok+1];
if (tb - tc < c - b) {
b = tb;
c = tc;
}
}
ok = i, ng = N;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (sum[mid] - sum[i] <= sum[N] - sum[mid]) ok = mid;
else ng = mid;
}
d = sum[ok] - sum[i], e = sum[N] - sum[ok];
if (ok + 1 < N) {
ll td = sum[ok+1] - sum[i], te = sum[N] - sum[ok+1];
if (td - te < e - d) {
d = td;
e = te;
}
}
chmin(res, max({b, c, d, e}) - min({b, c, d, e}));
}
cout << res << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
solve();
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }
vector<vector<int>> graph(100010, vector<int>());
vector<bool> vis(100010);
vector<int> t(100010, -1);
void dfs(int n, int c, bool &ok) {
t[n] = c;
vis[n] = true;
for (int i : graph[n]) {
if (vis[i]) {
if (t[i] == t[n]) {
ok = false;
}
continue;
}
dfs(i, c ^ 1, ok);
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
//modcalc();
int n, m;
cin >> n >> m;
vector<bool> check(n);
rep(i, m) {
int a, b;
cin >> a >> b;
a--; b--;
graph[a].pb(b);
graph[b].pb(a);
check[a] = true;
check[b] = true;
}
int ans = n * n;
int cnt = n;
rep(i, n) {
if (!check[i]) {
cnt--;
vis[i] = true;
}
}
ans -= cnt * cnt;
int x = 0, y = 0;
rep(i, n) {
bool oks = true;
if (!vis[i]) {
dfs(i, 0, oks);
if (oks) x++;
else y++;
}
}
ans += 2 * x + y + 2 * x*(x - 1) + 2 * x*y + y * (y - 1);
cout << ans << endl;
} | #include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
vector<int> get_bits(int mask) {
vector<int> bb;
while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
reverse(all(bb));
return bb;
}
int get_mask(vector<int> v) {
int mask = 0;
for(int x : v) { mask ^= (1 << x); }
return mask;
}
template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){
uniform_int_distribution<ll> uid(l, r);
return uid(rng);
}
void sc() {}
template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// #ifndef LOCAL
// string to_string(__int128 x) {
// string s = "";
// bool neg = 0;
// if(x < 0) { s += "-"; neg = 1; x = -x; }
// if(!x) s += '0';
// while(x) {
// int rem = x % 10;
// s += to_string(rem);
// x /= 10;
// }
// reverse(s.begin() + neg, s.end());
// return s;
// }
// #endif
const int mod = 1e9 + 7; // 998244353;
int pwr(int a,ll b) {
int ans = 1;
while(b) {
if(b & 1) ans = (ans * 1LL * a) % mod;
a = (a * 1LL * a) % mod;
b >>= 1;
}
return ans;
}
/*
Lookout for overflows!!
Check array sizes!!
Clear before test cases!!
Use the correct modulo!!
Check for corner cases!!
Are you forgetting something?!
Read problem statement carefully!!!
*/
const int N = 1e5 + 5;
int dsu[N], sz[N];
bool odd[N], par[N];
int root(int u) {
while(u != dsu[u]) u = dsu[u];
return u;
}
int get_par(int u) {
int p = 0;
while(u != dsu[u]) {
p ^= par[u];
u = dsu[u];
}
return p;
}
void uni(int u,int v) {
int uu = root(u), vv = root(v);
if(uu == vv) {
if(get_par(u) == get_par(v))
odd[uu] = 1;
return;
}
if(sz[uu] > sz[vv]) {
swap(uu, vv), swap(u, v);
}
dsu[uu] = vv;
sz[vv] += sz[uu];
odd[vv] |= odd[uu];
par[uu] = get_par(u) ^ get_par(v) ^ 1;
}
void solve() {
int n, m;
sc(n, m);
fr(i, 1, n) {
sz[i] = 1;
dsu[i] = i;
odd[i] = 0;
par[i] = 0;
}
fr(i, 1, m) {
int u, v;
sc(u, v);
uni(u, v);
}
int c1 = 0, c2 = 0, c3 = 0;
fr(i, 1, n) {
if(i == dsu[i]) {
if(sz[i] == 1) {
c1++;
}
else if(odd[i]) {
c2++;
}
else {
c3++;
}
}
}
ll ans = 0;
while(c1) {
ans += 2 * n - 1;
n--;
c1--;
}
while(c2) {
ans += 2 * (c2 + c3) - 1;
c2--;
}
ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3;
cout << ans;
}
int main() {
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
for(int tt = 1; tt <= t; tt++) {
solve();
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
int n; cin >> n;
vector<int> a(n+2);
a[0] = 0;
a[n+1] = 0;
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += abs(a[i] - a[i-1]);
}
sum += abs(a[n+1] - a[n]);
for (int i = 1; i <= n; i++) {
int diff = abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]) - abs(a[i+1] - a[i-1]);
cout << sum - diff << endl;
}
return 0;
} | #include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> vs;
int main(void){
map <char, int> m;
int num[] = {1,5,10,50,100,500,1000};
for (int i=0; i<7; i++)
m["IVXLCDM"[i]] = num[i];
char c;
string r;
while (cin>>r){
int tmp, tmp2= m[r[0]],s=0;
int n=r.size();
for (int i=0; i<n; i++){
tmp = m[r[i]];
if (tmp2<tmp)
s-= tmp2*2;
s += tmp;
tmp2 = tmp;
}
cout<<s<<endl;
}
} | 0 |
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
vector <int> edges[1000];
vector <int> cycle;
bool in_stack[1000];
bool done[1000];
set <pair <int, int> > edge_set;
int cycle_begin;
bool dfs_cycle(int cur){
in_stack[cur] = true;
cycle.push_back(cur);
done[cur] = true;
for(int i = 0; i < edges[cur].size(); i++){
int next = edges[cur][i];
if(in_stack[next]){
cycle_begin = next;
return true;
} else {
if(!done[next] && dfs_cycle(next)){
return true;
}
}
}
cycle.pop_back();
in_stack[cur] = false;
return false;
}
int main(void){
int N;
int M;
cin >> N >> M;
for(int i = 0; i < M; i++){
int a;
int b;
cin >> a >> b;
edges[a - 1].push_back(b - 1);
edge_set.insert(make_pair(a - 1, b - 1));
}
for(int i = 0; i < N; i++){
if(!done[i]){
if(dfs_cycle(i)){
break;
}
}
}
if(cycle.size() == 0){
cout << -1 << endl;
return 0;
}
vector <int> new_cycle;
for(int i = 0; i < cycle.size(); i++){
if(cycle[i] == cycle_begin){
for(int j = i; j < cycle.size(); j++){
new_cycle.push_back(cycle[j]);
}
break;
}
}
cycle = new_cycle;
while(true){
map <int, int> cycle_map;
for(int i = 0; i < cycle.size(); i++){
cycle_map[cycle[i]] = i;
//cout << cycle[i] << " ";
}
//cout << endl;
bool updated = false;
for(int u = 0; u < N; u++){
for(int j = 0; j < edges[u].size(); j++){
int v = edges[u][j];
if(cycle_map.find(u) != cycle_map.end()
&& cycle_map.find(v) != cycle_map.end()
&& (cycle_map[u] + 1) % cycle.size() != cycle_map[v]){
vector <int> next_cycle;
if(cycle_map[u] > cycle_map[v]){
for(int k = cycle_map[v]; k <= cycle_map[u]; k++){
next_cycle.push_back(cycle[k]);
}
} else {
for(int k = cycle_map[v]; k < cycle.size(); k++){
next_cycle.push_back(cycle[k]);
}
for(int k = 0; k <= cycle_map[u]; k++){
next_cycle.push_back(cycle[k]);
}
}
cycle = next_cycle;
updated = true;
break;
}
}
if(updated){
break;
}
}
if(!updated){
break;
}
}
cout << cycle.size() << endl;
for(int i = 0; i < cycle.size(); i++){
cout << cycle[i] + 1 << endl;
}
for(int i = 0; i < cycle.size(); i++){
if(edge_set.find(make_pair(cycle[i], cycle[(i + 1) % cycle.size()])) == edge_set.end()){
cout << "shit no edge!" << endl;
}
for(int j = 0; j < cycle.size(); j++){
if(i == j || (i + 1) % cycle.size() == j){
continue;
}
if(edge_set.find(make_pair(cycle[i], cycle[j])) != edge_set.end()){
cout << "shit" << endl;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, m, pre[1001];
bool vis[1001];
vector<int> adj[1001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
for(int i = 1; i <= n; i++){
memset(vis, 0, sizeof(vis));
memset(pre, 0, sizeof(pre));
stack<pair<int, int>> que;
que.push({i, 0});
while(!que.empty()){
pair<int, int> vtx = que.top();
que.pop();
vis[vtx.first] = true;
pre[vtx.first] = vtx.second;
for(auto j : adj[vtx.first])
if(j == i){
set<int> chn = {i};
int cur = vtx.first;
while(cur != i){
chn.insert(cur);
cur = pre[cur];
}
bool val = true;
for(auto k : chn){
int cnt = 0;
for(auto l : adj[k])
if(chn.find(l) != chn.end()) cnt++;
if(cnt > 1) val = false;
}
if(val){
cout << chn.size() << "\n";
for(auto k : chn) cout << k << "\n";
return 0;
}
}else if(!vis[j]) que.push({j, vtx.first});
}
}
cout << "-1\n";
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll N, M;
cin >> N >> M;
vec s(M), c(M);
REP(i,0,M) {
cin >> s[i] >> c[i];
--s[i];
}
ll d = 1;
bool f = true;
REP(i,0,N) d *= 10;
REP(i,N==1?0:d/10,d) {
string S = to_string(i);
f = true;
REP(j,0,M) {
if(!(s[j] < SZ(S) && S[s[j]]-'0' == c[j])) {
f = false;
break;
}
}
if(f) {
PR(i);
break;
}
}
if(!f) PR(-1);
return 0;
}
/*
*/ | #include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <limits.h>
using namespace std;
typedef long long ll;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
int main(void) {
int H, W;
cin >> H >> W;
vector<vector<int>> board(H, vector<int>(W));
for (int h = 0; h < H; h++) {
for (int w = 0; w < W; w++) {
cin >> board[h][w];
}
}
vector<pair<pair<int, int>, pair<int, int>>> cmds;
for (int h = 0; h < H; h++) {
if (h % 2 == 0) {
for (int w = 0; w < W; w++) {
int next_h, next_w;
if (w != W - 1) {
next_h = h;
next_w = w + 1;
} else {
next_h = h + 1;
next_w = w;
}
if (next_h >= H) {
continue;
}
if (board[h][w] % 2 != 0) {
board[h][w]--;
board[next_h][next_w]++;
cmds.push_back(make_pair(make_pair(h, w), make_pair(next_h, next_w)));
}
}
} else {
for (int w = W - 1; w >= 0; w--) {
int next_h, next_w;
if (w != 0) {
next_h = h;
next_w = w - 1;
} else {
next_h = h + 1;
next_w = w;
}
if (next_h >= H) {
continue;
}
if (board[h][w] % 2 != 0) {
board[h][w]--;
board[next_h][next_w]++;
cmds.push_back(make_pair(make_pair(h, w), make_pair(next_h, next_w)));
}
}
}
}
cout << cmds.size() << endl;
for (auto cmd : cmds) {
pair<int, int> src = cmd.first;
pair<int, int> dst = cmd.second;
printf("%d %d %d %d\n", src.first + 1, src.second + 1, dst.first + 1, dst.second + 1);
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;
#define rep(i,n) for(int i = 0; i < int(n); i++)
using namespace std;
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
constexpr ll mod = 1e9 + 7;
struct UnionFind {
public:
vector <ll> par; //
vector <ll> siz; //
UnionFind() {}
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) {
return root(x) == root(y);
}
ll size(ll x) {
return siz[root(x)];
}
};
int main() {
ll n;
cin >> n;
vector<int> ans;
for (int i = 0; i < 60; i++) {
ll m = n % (1LL << (i+1));
if (m) {
ans.push_back(1);
ll sub = 1LL << i;
if (i % 2 == 1) {
sub *= -1;
}
n -= sub;
}
else ans.push_back(0);
if (n == 0) break;
}
reverse(ans.begin(), ans.end());
for (auto a : ans) {
cout << a;
}
cout << endl;
return 0;
}
| #include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
if(N == 0) {cout << 0 << endl; return 0;}
int cnt = 0;
string A;
while(N != 0) {
if(cnt % 2 == 0) {
if(abs(N) % 2 == 1) {
N -= 1;
A = "1" + A;
} else {
A = "0" + A;
}
} else {
if(abs(N) % 2 == 1) {
N += 1;
A = "1" + A;
} else {
A = "0" + A;
}
}
N /= 2;
//N *= -1;
cnt++;
}
cout << A << endl;
return 0;
}
| 1 |
#include <iostream>
#include <functional> // std::function
#include <vector> // std::vector
struct edge {
using weight_type = size_t;
size_t to;
edge(size_t to) : to(to) { }
size_t cost() { return 1; }
};
struct graph {
using edge_type = edge;
const bool is_directed;
const size_t count_vertices;
std::vector<edge> *edges;
graph(size_t count_vertices, bool is_directed = true) : count_vertices(count_vertices), is_directed(is_directed) {
edges = new std::vector<edge>[count_vertices];
}
~graph() {
delete [] edges;
}
void make_edge(size_t from, size_t to) {
edges[from].push_back(edge(to));
if (!is_directed) {
edges[to].push_back(edge(from));
}
}
};
graph opposite_graph(const graph &g) {
size_t n = g.count_vertices;
graph op_g(n);
for (size_t u = 0; u < n; ++u) {
for (const edge &e: g.edges[u]) {
size_t v = e.to;
op_g.make_edge(v, u);
}
}
return op_g;
}
/*
template <class Graph>
std::vector<size_t> post_order_traversal(const Graph &g, size_t root) {
using Edge = typename Graph::edge_type;
size_t n = g.count_vertices;
std::vector<size_t> order;
std::vector<bool> used(n, false);
std::function<void(size_t)> dfs = [&](size_t u) {
printf("start node %d\n", u);
used[u] = true;
for (const Edge &e: g.edges[u]) {
size_t v = e.to;
if (!used[v]) {
dfs(v);
}
}
printf("end node %d\n", u);
order.push_back(u);
};
dfs(root);
return order;
}
*/
template <class Graph>
std::vector<size_t> strongly_connected_component(const Graph &g) {
using Edge = typename Graph::edge_type;
size_t n = g.count_vertices;
std::vector<bool> used(n, false);
std::vector<size_t> post_order;
std::function<void(size_t)> post_order_traversal = [&](size_t u) {
used[u] = true;
for (const Edge &e: g.edges[u]) {
size_t v = e.to;
if (!used[v]) {
post_order_traversal(v);
}
}
post_order.push_back(u);
};
for (size_t u = 0; u < n; ++u) {
if (!used[u]) {
post_order_traversal(u);
}
}
Graph op_g = opposite_graph(g);
std::vector<size_t> component(n, 123);
std::function<void(size_t, size_t)> dfs = [&](size_t u, size_t component_index) {
component[u] = component_index;
used[u] = true;
for (const Edge &e: op_g.edges[u]) {
size_t v = e.to;
if (!used[v]) {
dfs(v, component_index);
}
}
};
size_t count_components = 0;
fill(used.begin(), used.end(), false);
for (int i = n - 1; i >= 0; --i) {
size_t u = post_order[i];
if (!used[u]) {
dfs(u, count_components++);
}
}
return component;
}
int main() {
using namespace std;
int V, E;
cin >> V >> E;
graph g(V);
for (int i = 0; i < E; ++i) {
int u, v;
cin >> u >> v;
g.make_edge(u, v);
}
auto component = strongly_connected_component(g);
int Q;
cin >> Q;
for (int i = 0; i < Q; ++i) {
int u, v;
cin >> u >> v;
cout << (component[u] == component[v]) << '\n';
}
cout << flush;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
// cout << fixed << setprecision(10) << flush;
int n;
cin >> n;
vector<int> a(n), b(n), c(n);
vector<vector<int>> edge(n, vector<int>());
vector<vector<int>> weight(n, vector<int>());
for(int i=0; i<n-1; i++){
cin >> a[i] >> b[i] >> c[i];
a[i]--; b[i]--; c[i];
edge[a[i]].push_back(b[i]);
edge[b[i]].push_back(a[i]);
weight[a[i]].push_back(c[i]);
weight[b[i]].push_back(c[i]);
}
int q, k;
cin >> q >> k;
k--;
vector<int> dis(n, -1);
#if 0
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push(make_pair(0, k));
while(!pq.empty()){
int d = pq.top().first;
int p = pq.top().second;
pq.pop();
if(dis[p] != -1) continue;
dis[p] = d;
for(int i=0; i<edge[p].size(); i++){
int next = edge[p][i];
if(dis[next] == -1){
pq.push(make_pair(d + weight[p][i], next));
}
}
}
#else
stack<int> s;
s.push(k);
dis[k] = 0;
while(!s.empty()){
int p = s.top();
s.pop();
for(int i=0; i<edge[p].size(); i++){
int next = edge[p][i];
if(dis[next] == -1){
s.push(next);
dis[next] = dis[p] + weight[p][i];
}
}
}
#endif
for(int i=0; i<q; i++){
int x, y;
cin >> x >> y;
x--; y--;
cout << dis[x] + dis[y] << endl;
}
return 0;
} | 0 |
#include <cstdlib>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string str[2];
for (int i = 0; i < 2; i++)
{
getline(cin, str[i]);
// cout << "Input: " << str[i] << endl;
}
str[1] += ' ';
int num = atoi(str[0].c_str());
// cout << "Input Number: " << num << endl;
long* a = new long[num];
stringstream ss;
// ss = stringstream(str[1]);
ss << str[1];
string buff;
int n = 0;
while (getline(ss, buff, ' '))
{
if (n >= num) break;
a[n] = atoi(buff.c_str());
// cout << "Input Number: " << a[n] << endl;
n++;
}
for (int x = 0; x < num - 1; x++)
{
for (int y = 0; y < num - 1 - x; y++)
{
if (a[y] > a[y+1])
{
swap(a[y], a[y+1]);
}
}
// for (int i = 0; i < num; i++)
// {
// cout << "Step " << x << ": " << a[i] << endl;
// }
}
long min = a[0];
long max = a[num - 1];
long long sum = 0;
for (int i = 0; i < num; i++)
{
sum += a[i];
// cout << "Sorted Number: " << a[i] << endl;
}
delete [] a;
cout << min << " " << max << " " << sum << endl;
return 0;
}
| #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
using namespace std;
void Solution()
{
long int a;
cin>>a;
int b[10000] = {0};
long int sum = 0;
for (int i = 0; i < a; i++)
{
cin>>b[i];
sum = sum + b[i];
}
sort(b, b + a);
cout<<b[0]<<" "<<b[a - 1]<<" "<<sum<<endl;
}
int main()
{
Solution();
return 0;
} | 1 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);
int N;
string a0;
string ask(int i) {
out(i);
fflush(stdout);
string res;
cin >> res;
return res;
}
void f(int l, int r) {
int md = (l + r) / 2;
string res = ask(md);
if (res == "Vacant") return;
if ((md % 2 == 0 && a0 == res)
|| (md % 2 == 1 && a0 != res)) {
f(md + 1, r);
}
else {
f(l, md);
}
}
int main() {
cin >> N;
a0 = ask(0);
if (a0 == "Vacant") return 0;
f(1, N);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;
int main(){
ll n;
cin >> n;
cout << 0 << endl;
vector<string> ans(n);
cin >> ans[0];
if(ans[0] == "Vacant"){
return 0;
}
cout << n-1 << endl;
cin >> ans[n-1];
if(ans[n-1] == "Vacant"){
return 0;
}
ll right = n-1;
ll left = 0;
while(right-left > 1){
ll mid = (right+left)/2;
cout << mid << endl;
cin >> ans[mid];
if(ans[mid] == "Vacant") return 0;
else{
if((right-mid)%2 == 0 && ans[mid] != ans[right]){
left = mid;
}
else if((right-mid)%2 == 1 && ans[mid] == ans[right]){
left = mid;
}
else if((mid-left)%2 == 0 && ans[mid] != ans[left]){
right = mid;
}
else if((mid-left)%2 == 1 && ans[mid] == ans[left]){
right = mid;
}
}
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
cout << n / 3 << endl;
return 0;
} | #include <stdio.h>
int main() {
long long int N;
long long int total = 0;
scanf("%lld", &N);
int i;
for( i = 1; i <= N; i++){
if(i % 3 != 0 && i % 5 != 0 ){
total = total + i;
}
}
printf("%lld\n", total);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x) \
for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
T x;
cin >> x;
return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
cin >> head;
CIN(move(tail)...);
}
#define CINT(...) \
int __VA_ARGS__; \
CIN(__VA_ARGS__)
#define DCIN(...) \
double __VA_ARGS__; \
CIN(__VA_ARGS__)
#define LCIN(...) \
ll __VA_ARGS__; \
CIN(__VA_ARGS__)
#define SCIN(...) \
string __VA_ARGS__; \
CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v) \
{ \
FOREACH(x, v) { cout << x << " "; } \
cout << "\n"; \
}
template <typename T = string> inline void eputs(T s) {
cout << s << "\n";
exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;
typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};
void cinfast() {
cin.tie(0);
ios::sync_with_stdio(false);
}
VL mul(const VL &a, const VL &b) {
VL ret(a.size());
REP(i, a.size()) { ret[i] = a[b[i]]; }
return ret;
}
signed main() {
LCIN(N);
VL x(N);
VECCIN(x);
LCIN(M, K);
VL a(M);
REP(i, M) {
cin >> a[i];
a[i]--;
}
VL dx(N - 1);
REP(i, N - 1) dx[i] = x[i + 1] - x[i];
VL order(N - 1);
iota(All(order), 0);
REP(i, M) swap(order[a[i] - 1], order[a[i]]);
while(K) {
if(K & 1) dx = mul(dx, order);
order = mul(order, order);
K >>= 1;
}
VL ans(N);
ans[0] = x[0];
cout << ans[0] << "\n";
REP(i, N - 1) {
ans[i + 1] = ans[i] + dx[i];
cout << ans[i + 1] << "\n";
}
}
| #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};
ll mod(ll a, ll mod){
ll res = a%mod;
if(res<0)res=res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod){
ll res=1;
while(n>0){
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll modinv(ll a, ll mod){
ll b=mod, u=1, v=0;
while(b){
ll t=a/b;
a-=t*b; swap(a, b);
u-=t*v; swap(u, v);
}
u%=mod;
if(u<0)u+=mod;
return u;
}
ll gcd(ll a, ll b){
ll r = a%b;
if(r==0) return b;
else return gcd(b, a%b);
}
bool is_prime(ll n){
ll i = 2;
if(n==1)return false;
if(n==2)return true;
bool res = true;
while(i*i <n){
if(n%i==0){
res = false;
}
i = i+1;
}
//if(i==1)res = false;
if(n%i==0)res=false;
return res;
}
/**************************************
** A main function starts from here **
***************************************/
int main(){
ll N, T;
cin >> N >> T;
llvec v(N);
rep(i, N)cin >> v[i];
ll ans = 0;
rep(i, N-1){
ans += min(T, v[i+1] - v[i]);
}
cout << ans +T<< endl;
return 0;
}
| 0 |
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
string S;
cin >> S;
set<char> characters;
for(int i=0; i<S.size(); i++){
characters.insert(S.at(i));
}
char ans,check='a';
bool flag = true;
for(auto itr=characters.begin();
itr!=characters.end(); itr++){
if(*itr!=check){
ans=check;
break;
}
if(check=='z'){
flag = false;
break;
}
check++;
}
if(flag){
cout << ans;
}else{
cout << "None";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include <iostream>
#include <set>
int main(void){
string s;cin >> s;
vector<int> v(26,0);
for(char c:s) v[c-'a']++;
for(int i;i<26;i++){
if(!v[i]) {
char c = 'a' +i;
cout << c <<endl;
return 0;
}
}
cout << "None" << endl;
return 0;
} | 1 |
#include <iostream>
#include <vector>
using namespace std;
void printVector(const vector<int> &A) {
for(int i = 0; i < A.size(); i++) {
cout << A[i];
if(i+1 < A.size()) cout << ' ';
}
cout << endl;
}
int main() {
int n, count = 0;
auto swap = [](int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
};
cin >> n;
vector<int> A(n);
for(int i = 0; i < n; i++) {
cin >> A[i];
}
for(int i = 0; i < n-1; i++) {
for(int j = n-2; j >= i; j--) {
if(A[j] > A[j+1]) {
swap(A[j], A[j+1]);
count++;
}
}
}
printVector(A);
cout << count << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main(int argc,char** argv) {
int n,t;
vector<int> a;
cin >> n;
for(int i = 0;i < n;i++) {
cin >> t;
a.push_back(t);
}
bool flag = true;
int count = 0;
while(flag) {
flag = false;
for(auto itr = a.begin() + 1;itr != a.end();itr++) {
if(*itr < *(itr - 1)) {
iter_swap(itr,itr-1);
flag = true;
count++;
}
}
}
for(int i = 0;i < a.size()-1;i++) cout << a[i] << " ";
cout << a[a.size()-1] << endl << count << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int num(int N){
int a = 0 , b = 1, c;
for(int i = 0 ; i < 9 ; i++){
a += N / b % 10;
b *= 10;
}
c = N % a;
return c;
}
int main(){
int N;
cin >> N;
if(num(N) == 0){
cout << "Yes" <<endl;
}
else if(num(N) != 0){
cout << "No" << endl;
}
} | #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }
ll INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s; cin>>s;
ll f = 0;
ll n = sz(s);
rep(i, n) {
f += s[i] - '0';
}
if (stoi(s) % f == 0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
} | 1 |
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;
int main(){
int n,q;
cin >> n >> q;
vector <int> res;
int a[n];
int sq = sqrt(n);
int nsq = n/sq+1;
int lazy[nsq];
fill(a,a+n,2147483647);
fill(lazy,lazy+nsq,-1);
REP(i,q){
int z;
cin >> z;
if(z == 0){
int s,t,x;
cin >> s >> t >> x;
/*if(s == t){
a[s] = x;
}*/
if(t/sq == s/sq){
if(lazy[t/sq] >= 0){
fill_n(a+(t/sq)*sq,sq,lazy[t/sq]);
lazy[t/sq] = -1;
}
if(t-s+1 == sq){
lazy[t/sq] = x;
}
else{
fill_n(a+s,t-s+1,x);
}
//cout << "debug1" <<endl;
}
else{
//cout << "debug3" << endl;
int f = s,to = t;
while(to%sq != (sq - 1)){
to--;
}
while(f%sq != 0){
f++;
}
if(lazy[t/sq] >= 0){
fill_n(a+(t/sq)*sq,sq,lazy[t/sq]);
}
if(lazy[s/sq] >= 0){
fill_n(a+(s/sq)*sq,sq,lazy[s/sq]);
}
fill_n(a+to+1,t-to,x);
lazy[t/sq] = -1;
fill_n(a+s,f-s,x);
lazy[s/sq] = -1;
f = f/sq;
to = to/sq;
if(f <= to){
fill_n(lazy+f,to-f+1,x);
}
}
/*REP(i,n)
cout << a[i] << " ";
cout << endl;*/
}
else{
int x;
cin >> x;
int te = x / sq;
if(lazy[te] < 0){
//cout << a[x] << endl;
res.pb(a[x]);
}
else{
fill_n(a+te*sq,sq,lazy[te]);
lazy[te] = -1;
//cout << a[x] << endl;
res.pb(a[x]);
}
}
}
for(int i = 0;i < res.size();i++){
cout << res[i] << endl;
}
//cout << res.size() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}
using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;
const int inf = (1LL<<31)-1;
const int mod = 1e9 + 7;
struct SegmentTree {
vector<int> data, lazy;
int sz;
SegmentTree(int n) {
sz = 1; while(sz < n) sz <<= 1;
data.resize(2*sz-1, inf);
lazy.resize(2*sz-1, -1);
}
void lazy_evaluate(int k, int l, int r) {
if(~lazy[k]) {
data[k] = lazy[k];
if(r - l > 1) {
lazy[2*k+1] = lazy[k];
lazy[2*k+2] = lazy[k];
}
lazy[k] = -1;
}
}
void update(int a, int b, int x, int k, int l, int r) {
lazy_evaluate(k, l, r);
if(r <= a || b <= l) return;
if(a <= l && r <= b) {
lazy[k] = x;
lazy_evaluate(k, l, r);
return;
}
update(a, b, x, 2*k+1, l, (l+r)/2);
update(a, b, x, 2*k+2, (l+r)/2, r);
}
void update(int a, int b, int x) {
update(a, b, x, 0, 0, sz);
}
int query(int i, int k, int l, int r) {
lazy_evaluate(k, l, r);
if(r - l == 1) return data[k];
if(l <= i && i <= r) {
if(i < (l+r)/2) return query(i, 2*k+1, l, (l+r)/2);
else return query(i, 2*k+2, (l+r)/2, r);
}
return inf;
}
int query(int i) {
return query(i, 0, 0, sz);
}
};
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int n, q;
cin >> n >> q;
SegmentTree seg(n);
rep(i, q) {
int com, s, t, x;
cin >> com >> s;
if(com == 0) cin >> t >> x, seg.update(s, t+1, x);
else cout << seg.query(s) << endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
int b;
cin>>a>>b;
for(int i=0;i<a.size();i+=b){
cout<<a.at(i);
}
cout<<endl;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
ll a;
cin >> a;
ll ans = 999;
while(a>99){
ans = min(ans,abs(753-a%1000));
a /= 10;
}
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
string s;
cin>>s;
bool f=true;
long long ans=0;
if(s[0]!='A'){
f=false;
}
f(i,2,s.size()-1){
if(s[i]=='C'){
ans++;
}
else if(s[i]-'a'<0){
f=false;
}
}
if(s[1]-'a'<0||s[s.size()-1]-'a'<0){
f=false;
}
if(f&&ans==1){
cout<<"AC"<<endl;
}
else{
cout<<"WA"<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001
vector<ll> enum_divisors(ll N) {
vector<ll> res;
for (ll i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N/i != i) res.push_back(N/i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
return res;
}//vector<ll>で受け取ること!
int main() {
ll n;cin >> n;
vector<ll> a=enum_divisors(n);
ll x=a[a.size()/2];
ll y=n/x;
ll p=1,q=1;
while(x>=10){
x /= 10;
p++;
}
while(y>=10){
y /= 10;
q++;
}
cout << max(p,q) << endl;
return 0;
} | 0 |
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());
using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;
int main() {
std::vector<int> v(3);
rep(i,3) cin >> v[i];
sort(v.rbegin(), v.rend());
debug(v);
int num; cin>>num;
rep(i, num) {
v[0] *= 2;
sort(v.rbegin(), v.rend());
}
int sum = accumulate(ALL(v), 0);
cout << sum << endl;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
int main(){
int n;
cin >> n;
vector<vector<int>> v(n,vector<int>(n-1));
rep(i,n)rep(j,n-1)cin >> v[i][j],v[i][j]--;
set<P> st;
vector<P> nxt;
rep(i,n){
if(i < v[i][0])nxt.push_back(make_pair(v[i][0],i));
else nxt.push_back(make_pair(i,v[i][0]));
}
vector<int> l(n,1);
int roop = n*(n-1)/2;
ll res = 0;
while(roop){
if(nxt.empty())break;
vector<P> k;
for(auto au : nxt){
if(st.count(au)){
roop--;
if(l[au.first] < n-1)k.push_back(make_pair(max(au.first,v[au.first][l[au.first]]),min(au.first,v[au.first][l[au.first]])));
if(l[au.second] < n-1)k.push_back(make_pair(max(au.second,v[au.second][l[au.second]]),min(au.second,v[au.second][l[au.second]])));
l[au.first]++;
l[au.second]++;
}else{
st.insert(au);
}
}
nxt = k;
res++;
}
cout << (!roop ? res : -1) << endl;
return 0;
} | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
void darts();
void longest_dis();
void sum_of_three_integers();
void otoshidama();
int main()
{
//darts();
//longest_dis();
//sum_of_three_integers();
otoshidama();
}
void darts()
{
while (true)
{
int n, m;
cin >> n >> m;
// stop cond
if (n == 0) break;
vector<int> p(n);
for (int i = 0; i < n; ++i) cin >> p[i];
// 2 darts combination
// p = q, 0, p + q
vector<int> q = p;
q.push_back(0);
for (int i = 0; i < n; ++i)
{
for (int j = 0; j <= i; ++j)
{
q.push_back(p[i] + p[j]);
}
}
sort(q.begin(), q.end());
// q's size = 1 + n + n(n + 1) / 2
//cout << q.size() << "\n";
//for (auto x : q) cout << x << " ";
int ret = 0;
int j = q.size() - 1;
//i:q linear scan
for (int i = 0; i < q.size(); ++i)
{
if (q[i] > m) break;
while (q[i] + q[j] > m) --j;
ret = max(ret, q[i] + q[j]);
}
cout << ret << "\n";
}
}
void longest_dis()
{
int n;
cin >> n;
vector<pair<int, int>> p(n);
for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;
double v_max = 0.0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if ((p[i].first - p[j].first) * (p[i].first - p[j].first)
+ (p[i].second - p[j].second) * (p[i].second - p[j].second)
> v_max * v_max)
{
v_max = sqrt((p[i].first - p[j].first) * (p[i].first - p[j].first)
+ (p[i].second - p[j].second) * (p[i].second - p[j].second));
}
}
}
cout << v_max << "\n";
}
void sum_of_three_integers()
{
int k, s;
cin >> k >> s;
int cnt = 0;
//for (int i = 0; i <= k; ++i)
//{
// for (int j = 0; j <= k; ++j)
// {
// for (int m = 0; m <= k; ++m)
// {
// if (i + j + m == s) ++cnt;
// }
// }
//}
for (int i = 0; i <= k; ++i)
{
for (int j = 0; j <= k; ++j)
{
int m = s - i - j;
if (0 <= m && m <= k) ++cnt;
}
}
cout << cnt << "\n";
}
void otoshidama()
{
int n, Y;
cin >> n >> Y;
for (int x = 0; x <= n; ++x)
{
for (int y = 0; x + y <= n; ++y)
{
int z = n - x - y;
if (x * 10000 + y * 5000 + z * 1000 == Y)
{
cout << x << " "<< y << " " << z << "\n";
return;
}
}
}
cout << "-1 -1 -1\n";
} | #include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265359
using namespace std;
int main() {
int n;
cin >> n;
int x[n], y[n];
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++) {
double l1 = 0, r1 = PI, l2 = - PI, r2 = 0;
for (int j = 0; j < n; j++) {
if (i != j) {
double th = atan2(y[j] - y[i], x[j] - x[i]);
//cout << th << " ";
if (th < -0.5 * PI && x[i] != x[j]) {
l2 = max(l2, th + PI * 0.5);
r1 = min(r1, th + PI * 1.5);
} else if (th < 0.5 * PI || x[i] == x[j]) {
l1 = max(l1, th + PI * 0.5);
r2 = min(r2, th - PI * 0.5);
} else {
l2 = max(l2, th - PI * 1.5);
r1 = min(r1, th - PI * 0.5);
}
//cout << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
}
}
printf("%.10lf\n", max(0., (r1 - l1) / 2 / PI) + max(0., (r2 - l2) / 2 / PI));
}
return 0;
} | 0 |
#include<stdio.h>
int main(){
int tab[101][3];
int n,a,b,c,d,e,i,j,k,m,t,max,mx,cnt,cn;
for(i=0;i<101;i++){
tab[i][0]=0;
tab[i][1]=i;
tab[i][2]=0;
}
scanf("%d",&n);
m=n*(n-1)/2;
for(k=0;k<m;k++){
scanf("%d %d %d %d",&a,&b,&c,&d);
if(c>d){
tab[a][0]+=3;
}else if(c<d){
tab[b][0]+=3;
}else if(c==d){
tab[a][0]++;
tab[b][0]++;
}
}
//for(i=1;i<=n;i++)printf("%d\n",tab[i][0]);
for(i=n;i>0;i--){
for(j=1;j<i;j++){
if(tab[j][0]<tab[j+1][0]){
t=tab[j][0];
tab[j][0]=tab[j+1][0];
tab[j+1][0]=t;
t=tab[j][1];
tab[j][1]=tab[j+1][1];
tab[j+1][1]=t;
}
}
}
cnt=1;
cn=1;
//for(i=1;i<=n;i++)printf("%d %d\n",tab[i][0],tab[i][1]);
t=tab[1][0];
tab[1][2]=cnt;
for(i=2;i<=n;i++){
if(tab[i][0]==t){
tab[i][2]=cnt;
cn++;
}else{
cnt+=cn;
cn=1;
t=tab[i][0];
tab[i][2]=cnt;
}
}
//for(i=1;i<=n;i++)printf("%d %d\n",tab[i][0],tab[i][2]);
for(i=n;i>0;i--){
for(j=1;j<i;j++){
if(tab[j][1]>tab[j+1][1]){
t=tab[j][2];
tab[j][2]=tab[j+1][2];
tab[j+1][2]=t;
t=tab[j][1];
tab[j][1]=tab[j+1][1];
tab[j+1][1]=t;
}
}
}
for(i=1;i<=n;i++)printf("%d\n",tab[i][2]);
return 0;
} | #include <iostream>
#include <bits/stdc++.h>
#define mod 998244353
#define point complex<double>
#define pi acos(-1)
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
void Fastio(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ld n, dp[305][305][305];
ld solve(int i, int y, int j){
if(i+y+j==0)
return 0;
if(dp[i][y][j]!=-1)
return dp[i][y][j];
ld res=1, c0 = ( i + y + j);
if(i)res+=solve(i-1, y+1, j)*((ld)i)/n;
if(y)res+=solve(i, y-1, j+1)*((ld)y)/n;
if(j)res+=solve(i, y, j-1)*((ld)j)/n;
return dp[i][y][j]=res / c0 * n;
}
int main()
{
Fastio();
int ttt=1; //cin>>ttt;
while(ttt--){
cin>>n;
int c1=0, c2=0, c3=0;
for(int i=0; i<n; i++){
int x; cin>>x;
if(x==1)c1++;
else if(x==2)c2++;
else c3++;
}
for(int i=0; i<305; i++){
for(int y=0; y<305; y++){
for(int j=0; j<305; j++){dp[i][y][j]=-1;}
}
}
cout<<fixed<<setprecision(9)<<solve(c3, c2, c1)<<'\n';
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
char turn = 'a';
string a, b, c;
int i = 0, j = 0, k = 0;
cin >> a >> b >> c;
while (i <= a.size() && j <= b.size() && k <= c.size())
{
if (turn == 'a')
turn = a[i++];
else if (turn == 'b')
turn = b[j++];
else
turn = c[k++];
}
if (i > a.size()) cout << "A" << endl;
else if (j > b.size()) cout << "B" << endl;
else cout << "C" << endl;
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;
// -------------------------------------------------------
string s[3];
int cnt[3];
int main() {
cin >> s[0] >> s[1] >> s[2];
int cur = 0;
while (cnt[cur] < s[cur].size()) {
int next = s[cur][cnt[cur]] - 'a';
++cnt[cur];
cur = next;
}
char ans = 'A' + cur;
cout << ans;
}
| 1 |
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define all(x) (x).begin(),(x).end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n;cin>>n;
cout<<(n-2)*180<<endl;
return 0;
}
| /*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
using ll = long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);
using namespace std;
void scans(string& str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')scanf("%c", &c);//最初の改行対策
while (c != '\n' && c != -1) {
str += c;
scanf("%c", &c);
}
}
void scanc(char& str) {
char c;
scanf("%c", &c);
if (c == -1)return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) {
return PI / 2 - atan(x);
}
/*-----------------------------------------ここからコード-----------------------------------------*/
int main() {
int a;
scanf("%d", &a);
printf("%d\n", 180 * (a - 2));
Please AC;
}
| 1 |
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<complex>
#define rep(i, a, n) for(int i=a;i<n;i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define R long double
#define P complex<R>
using namespace std;
const int mod = 1000000007;
const int INF = 1e12;
template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}
const R PI = acos(-1.0L);
const R inf = 1e13;
int x[110], y[110];
R ans[110];
inline R dist(int i, P q) {
P p = P(x[i], y[i]);
return norm(p - q);
}
signed main(){
int n;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>x[i]>>y[i];
}
int limit = 200000;
rep(i, 0, limit){
R cur = 2.0 * PI / limit * i;
P point = polar(inf, cur);
R d = 1e130;
int idx = -1;
rep(j, 0, n) if(chmin(d, dist(j, point))) idx = j;
ans[idx] += 1.0;
}
cout.precision(20);
rep(i, 0, n) cout << fixed << 1.0 * ans[i] / limit << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> duo;
#define TT template<typename T>
TT T sq(T x){ return x*x; }
TT int ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(T& x){ cin >> x; return x; }
static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
struct Rect {
int h, w, d;
Rect(int h, int w) : h(h), w(w), d(sq(h) + sq(w)) {}
bool operator<(const Rect& x) const {
return d == x.d ? h < x.h : d < x.d;
}
};
int main()
{
vector<Rect> v;
int h, w;
for (int x = 1; x <= 150; x++){
for (int y = 1; y < x; y++){
v.push_back(Rect(y, x));
}
}
sort(v);
while (h = in(), w = in(), h || w){
Rect r = Rect(h, w);
int index = ubnd(v, r);
printf("%d %d\n", v[index].h, v[index].w);
}
return (0);
} | 0 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <iterator>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int N,M,B;
int A[1000];
int C[1000];
int main(){
cin>>N>>M;
FOR(i,0,N){
cin>>A[i];
}
FOR(i,0,M){
cin>>B;
int j=0;
while(B<A[j]){
j++;
}
C[j]++;
}
int M=0,ans;
FOR(i,0,N){
if(M<C[i]){
M=C[i];
ans=i+1;
}
}
cout<<ans<<endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int a , b;
cin>>a>>b;
int ans =0;
for(int i=a;i<=b;i++)
{
string temp = to_string(i);
string temp1 = temp;
reverse(temp1.begin() , temp1.end());
if( temp == temp1)
ans++;
}
cout<<ans;
} | 0 |
#if 0
date +%Y.%m.%d
题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long ll;
struct {
inline operator int () { int x; return scanf("%d", &x), x; }
inline operator ll () { ll x; return scanf("%lld", &x), x; }
template<class T> inline void operator () (T &x) { x = *this; }
template<class T, class ...A> inline void operator () (T &x, A &...a)
{ x = *this; this -> operator ()(a...); }
} read;
const int maxn = 200005;
ll f[maxn << 2], fa[maxn << 2], fb[maxn << 2], tag;
void modify(int now, int L, int R, int p, ll x) {
f[now] = std::min(f[now], x);
fa[now] = std::min(fa[now], x + p);
fb[now] = std::min(fb[now], x - p);
if(L == R) return;
int M = (L + R) >> 1;
if(p <= M) modify(now << 1, L, M, p, x);
else modify(now << 1 | 1, M + 1, R, p, x);
}
void build(int now, int L, int R) {
f[now] = fa[now] = fb[now] = 1000000000000000000;
if(L == R) return;
int M = (L + R) >> 1;
build(now << 1, L, M);
build(now << 1 | 1, M + 1, R);
}
ll query(int now, int L, int R, int p) {
if(R < p) return p + fb[now];
if(L > p) return fa[now] - p;
if(L == R) return f[now];
int M = (L + R) >> 1;
return std::min(query(now << 1, L, M, p), query(now << 1 | 1, M + 1, R, p));
}
void test(int now, int L, int R) {
/* debug("%d-%d : %lld (+)%lld (-)%lld\n", */
/* L, R, f[now] + tag, fa[now] + tag, fb[now] + tag); */
if(L == R) {
/* if(f[now] >= 1000000000) */
/* debug(" inf"); */
/* else */
/* debug(" %lld", f[now] + tag); */
return;
}
int M = (L + R) >> 1;
test(now << 1, L, M);
test(now << 1 | 1, M + 1, R);
}
int main() {
int n = read, q = read, a = read, b = read;
build(1, 1, n);
modify(1, 1, n, a, 0);
/* modify(1, 1, n, b, 0); */
int last = b;
while(q --) {
int x = read;
ll qu = query(1, 1, n, x) + tag;
/* debug("qu = %lld\n", qu); */
tag += std::abs(x - last);
modify(1, 1, n, last, qu - tag);
last = x;
/* debug("tag=%lld\n", tag); */
/* test(1, 1, n); debug("\n"); */
}
printf("%lld\n", f[1] + tag);
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
int x = 0; char ch = gc(); bool positive = 1;
for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0;
for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(int a){
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(int a){
if(a<0){
a=-a; putchar('-');
}
write(a); puts("");
}
const int N=200005;
int n,q,x,y,a[N];
ll sum[N],dp[N],ans;
#define lowbit(i) i&-i
struct BIT{
ll c[N];
void change(int pos,ll de){
for(int i=pos;i<=n;i+=lowbit(i))c[i]=min(c[i],de);
}
ll ask(int pos){
ll ans=4e18;
for(int i=pos;i;i-=lowbit(i))ans=min(ans,c[i]);
return ans;
}
}T[2];
void insert(ll de,int pos){
T[0].change(pos,de-pos);
T[1].change(n-pos+1,de+pos);
}
int main(){
n=read(); q=read(); x=read(); y=read();
for(int i=1;i<=q;i++)a[i]=read();
for(int i=2;i<=q;i++)sum[i]=sum[i-1]+abs(a[i-1]-a[i]);
for(int i=1;i<=n;i++)T[0].c[i]=T[1].c[i]=4e18;
insert(abs(x-a[1]),y);
insert(abs(y-a[1]),x);
ans=sum[q]+min(abs(x-a[1]),abs(y-a[1]));
for(int i=1;i<q;i++){
dp[i]=min(T[0].ask(a[i+1])+sum[i]+a[i+1],T[1].ask(n-a[i+1]+1)+sum[i]-a[i+1]);
//if(i==3)cout<<dp[i]<<" "<<i<<" "<<T[0].ask(a[i+1])<<endl;
//cout<<ans<<endl;
ans=min(ans,dp[i]+sum[q]-sum[i+1]);
insert(dp[i]-sum[i+1],a[i]);
}
cout<<ans<<endl;
}
/*
dp[i]=dp[j]+sum[i]-sum[j+1]+abs(a[i+1]-a[j])
*/ | 1 |
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 345;
double dp[MAXN][MAXN][MAXN];
bool visit[MAXN][MAXN][MAXN];
double dfs(int c1, int c2, int c3, int N) {
if (visit[c1][c2][c3]) return dp[c1][c2][c3];
visit[c1][c2][c3] = 1;
if (!c1 && !c2 && !c3) return 0.0;
int c0 = N - c1 - c2 - c3;
double res = (double)c0 / N;
if (c1) res += (dfs(c1 - 1, c2, c3, N) + 1) * ((double)c1 / N);
if (c2) res += (dfs(c1 + 1, c2 - 1, c3, N) + 1) * ((double)c2 / N);
if (c3) res += (dfs(c1, c2 + 1, c3 - 1, N) + 1) * ((double)c3 / N);
return dp[c1][c2][c3] = ((double)N / (N - c0) * res);
}
int main() {
int N;
scanf("%d", &N);
vector<int> cnt(4, 0);
for (int i = 0; i < N; i++) {
int a;
scanf("%d", &a);
cnt[a]++;
}
printf("%.10lf\n", dfs(cnt[1], cnt[2], cnt[3], N));
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
by Benq;
*/
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
int n;cin>>n;
vector<vector<int>> a(n,vector<int>(n-1));
rep(i,n)rep(j,n-1){
cin>>a[i][j];
a[i][j]--;
}
int f=0;
vector<int> t(n,0);
queue<int> que;
rep(i,n)que.push(i);
ll res=0;
while(true){
res++;
queue<int> que2;
bool used=false;
vector<bool> ft(n,false);
while(que.size()){
int x=que.front();que.pop();
if(ft[x])continue;
int op=a[x][t[x]];
if(ft[op])continue;
if(a[op][t[op]]==x){
used=true;
ft[x]=ft[op]=true;
t[x]++;t[op]++;
if(t[x]==n-1)f++;
else que2.push(x);
if(t[op]==n-1)f++;
else que2.push(op);
}
}
if(!used){
cout<<-1<<endl;
return 0;
}
if(f==n){
cout<<res<<endl;
return 0;
}
swap(que,que2);
}
} | 0 |
#include "bits/stdc++.h"
#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}
using namespace std;
using ll = long long;
constexpr ll atcoder_mod = 1e9+7;
template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}
void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}
vector<string> split_naive(const string &s, char delim) {
vector<string> elems;
string item;
for(char ch:s){
if(ch==delim){
if(!item.empty()) elems.push_back(item);
item.clear();
}
else{
item += ch;
}
}
if(!item.empty()) elems.push_back(item);
return elems;
}
int main(){
//cin.tie(0);
//ios::sync_with_stdio(false);
string S;
while(cin>>S){
auto SS=split_naive(S,',');
vector<int> C(5);
map<int,int> M;
REP(i,5){
sscanf(SS[i].c_str(),"%d",&C[i]);
M[C[i]]++;
}
sort(ALL(C));
int two=0,three=0,four=0;
for(auto& x:M){
if(x.second==2) two++;
else if(x.second==3) three++;
else if(x.second==4) four++;
}
if(four){
out("four card");
}
else if(three){
if(two){
out("full house");
}
else{
out("three card");
}
}
else if(two){
if(two==2){
out("two pair");
}
else{
out("one pair");
}
}
else{
bool straight = true;
if(C[0]==1){
if(C[1]==2 || C[1]==10){
for(int i=1;i<4;i++){
if(C[i+1]!=C[i]+1){
straight = false;
break;
}
}
}
else{
straight = false;
}
}
else{
REP(i,4){
if(C[i+1]!=C[i]+1){
straight = false;
break;
}
}
}
if(straight){
out("straight");
}
else{
out("null");
}
}
}
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
#define nullptr NULL
struct node
{
int val;
node* right;
node* left;
node(const int& v = 0) : val(v), right(nullptr), left(nullptr)
{}
};
struct Tree
{
node* root;
};
node* insert(node* root, int v)
{
if (!root)
{
root = new node(v);
return root;
}
node* temp = root;
while (1)
{
if (root->val > v)
{
if (!root->left)
{
root->left = new node(v);
break;
}
root = root->left;
}
else
{
if (!root->right)
{
root->right = new node(v);
break;
}
root = root->right;
}
}
return temp;
}
node* remove(node* root, int v)
{
if (!root)
return nullptr;
if (root->val > v)
root->left = remove(root->left, v);
else if (root->val < v)
root->right = remove(root->right, v);
else
{
if (!root->left || !root->right)
{
root = (root->left) ? root->left : root->right;
}
else
{
node* temp = root->right;
while (temp->left)
temp = temp->left;
root->val = temp->val;
root->right = remove(root->right, temp->val);
}
}
return root;
}
node* find(node* root, int v)
{
if (!root)
return nullptr;
while (root != nullptr && v != root->val)
{
if (v < root->val)
root = root->left;
else
root = root->right;
}
return root;
}
void preorder(node* root)
{
if (!root)
return;
cout << " " << root->val;
preorder(root->left);
preorder(root->right);
}
void inorder(node* root)
{
if (!root)
return;
inorder(root->left);
cout << " " << root->val;
inorder(root->right);
}
int main()
{
int m;
node* root = nullptr;
cin >> m;
for (int i = 0; i < m; i++)
{
int k;
string s;
cin >> s;
if (s == "insert")
{
cin >> k;
root = insert(root, k);
}
else if (s == "delete")
{
cin >> k;
root = remove(root, k);
}
else if (s == "find")
{
cin >> k;
if (find(root, k) != nullptr)
cout << "yes" << endl;
else
cout << "no" << endl;
}
else if (s == "print")
{
inorder(root);
cout << endl;
preorder(root);
cout << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
// typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;
const lli e5 = 1 << 20;
const lli mod = 998244353;
const lli e3 = 1 << 12;
lli n,m,q;
lli s[e3][e3];
lli query[e5][4];
lli v_edge[e3][e3];
lli h_edge[e3][e3];
int main(){
cin >> n >> m >> q;
for(lli i = 1;i <= n;i++){
string hoge;
cin >> hoge;
for(lli j = 0;j < m;j++){
s[i][j+1] = hoge[j]-'0';
}
}
for(lli i = 0;i < q;i++){
for(lli j = 0;j < 4;j++) cin >> query[i][j];
}
for(lli i = 1;i < n;i++){
for(lli j = 1;j <= m;j++){
v_edge[i][j] = (s[i][j] == 1 && s[i+1][j] == 1);
}
}
for(lli i = 1;i <= n;i++){
for(lli j = 1;j < m;j++){
h_edge[i][j] = (s[i][j] && s[i][j+1] == 1);
}
}
// s
for(lli i = 1;i <= n;i++){
for(lli j = 1;j <= m;j++){
s[i][j] += s[i-1][j];
}
}
for(lli i = 1;i <= n;i++){
for(lli j = 1;j <= m;j++){
s[i][j] += s[i][j-1];
}
}
// v_edge
for(lli i = 1;i < n;i++){
for(lli j = 1;j <= m;j++){
v_edge[i][j] += v_edge[i-1][j];
}
}
for(lli i = 1;i < n;i++){
for(lli j = 1;j <= m;j++){
v_edge[i][j] += v_edge[i][j-1];
}
}
// h_edge
for(lli i = 1;i <= n;i++){
for(lli j = 1;j < m;j++){
h_edge[i][j] += h_edge[i-1][j];
}
}
for(lli i = 1;i <= n;i++){
for(lli j = 1;j < m;j++){
h_edge[i][j] += h_edge[i][j-1];
}
}
for(lli i = 0;i < q;i++){
lli vertices = s[query[i][2]][query[i][3]]
-s[query[i][2]][query[i][1]-1]
-s[query[i][0]-1][query[i][3]]
+s[query[i][0]-1][query[i][1]-1];
lli v = v_edge[query[i][2]-1][query[i][3]]
-v_edge[query[i][2]-1][query[i][1]-1]
-v_edge[query[i][0]-1][query[i][3]]
+v_edge[query[i][0]-1][query[i][1]-1];
lli h = h_edge[query[i][2]][query[i][3]-1]
-h_edge[query[i][2]][query[i][1]-1]
-h_edge[query[i][0]-1][query[i][3]-1]
+h_edge[query[i][0]-1][query[i][1]-1];
// cerr << vertices << " " << v << " " << h << endl;
cout << vertices-v-h << endl;
}
}
| /* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define ull unsigned long long
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 4e6 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr
#endif
#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif
const int M = 2005 ;
// l = 0 , r = 1 , u = 2 , d = 3 , no = 4;
int dx[] = {0 , 0 , -1 , 1};
int dy[] = {-1, 1 , 0 , 0};
int ad[5][M][M];
int g[M][M] ;
int ok(int i , int j , int n , int m){
bool ans1 = (i >= 0 && i < n);
bool ans2 = (j >= 0 && j < m);
return ans1 && ans2 ;
}
int sqsum(int k , int lx , int ly , int rx , int ry){
int res = ad[k][rx][ry];
if(lx) res -= ad[k][lx-1][ry];
if(ly) res -= ad[k][rx][ly - 1];
if(lx && ly) res += ad[k][lx-1][ly-1];
return res ;
}
void solve()
{
int n , m , q ;
cin >> n >> m >> q;
string s[n] ;
rep(i , n){
cin >> s[i] ;
rep(j , m)
g[i][j] = s[i][j] - '0';
}
rep(i , n) rep(j , m){
if(g[i][j]){
rep(k , 4) ad[k][i][j] = (ok(i + dx[k] , j + dy[k] , n , m) && g[i + dx[k]][j + dy[k]]);
}
ad[4][i][j] = g[i][j];
}
rep(k , 5){
rep(i , n) rep(j , m){
if(i) ad[k][i][j] += ad[k][i-1][j] ;
if(j) ad[k][i][j] += ad[k][i][j-1] ;
if(i && j) ad[k][i][j] -= ad[k][i-1][j-1];
}
}
while(q--){
int lx, ly, rx, ry;
cin >> lx >> ly >> rx >> ry;
lx--, ly--, rx--, ry-- ;
int edges = 0;
rep(k , 4) edges += sqsum(k , lx , ly , rx , ry);
edges -= sqsum(0 , lx , ly , rx, ly);
edges -= sqsum(1 , lx, ry, rx, ry);
edges -= sqsum(2 , lx , ly , lx, ry);
edges -= sqsum(3 , rx, ly, rx, ry);
int nodes = sqsum(4, lx, ly, rx, ry);
// cout << nodes << " " << edges/2 << "\n" ;
cout << nodes - edges/2 << "\n" ;
}
}
int32_t main(int32_t argc, char *argv[])
{
double t1 = clock() ;
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1, t = 0;
//cin >> TC ;
while(t++ < TC)
{
//cout << "Case #" << t << ": " ;
solve();
//cout << endl ;
}
mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
return 0;
} | 1 |
#include "bits/stdc++.h"
using namespace std;
#define ASC(vec) vec.begin(), vec.end() // 昇順ソート 例:sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)
const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;
template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }
constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
// ──────────────────────────────────────────────────────────────────
int dp[101][9];
int main() {
int h, w, k;
cin >> h >> w >> k;
vvi dp(h + 1, vi(w));
dp[0][0] = 1;
rep(i, h) {
rep(j, w) {
rep(bit, (1 << (w - 1))) {
bool ok = true;
rep(k, w - 2) {
if ((bit >> k) & 1 && (bit >> (k + 1)) & 1) {
ok = false;
break;
}
}
if (ok) {
if (j >= 1 && ((bit >> (j - 1)) & 1)) {
dp[i + 1][j - 1] += dp[i][j];
dp[i + 1][j - 1] %= mod;
}
else if (j <= w - 2 && ((bit >> j) & 1)) {
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j + 1] %= mod;
}
else {
dp[i + 1][j] += dp[i][j];
dp[i + 1][j] %= mod;
}
}
}
}
}
cout << dp[h][k - 1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
long long fact[200009], inv_fact[200009];
long long modpow(long long a, long long n, long long mod){
long long ret = 1;
while(n>0){
if(n&1)ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
long long modinv(long long a, long long mod){
return modpow(a, mod-2, mod);
}
long long nCr(long long n, long long r, long long mod){
return (((fact[n]*inv_fact[n-r])%MOD)*inv_fact[r])%MOD;
}
int main(){
long long n, m, k;
cin >>n >> m >> k;
long long cnt=0;
fact[0]=1;inv_fact[0]=1;
for(int i=1;i<=n;i++){
fact[i]=(fact[i-1]*i)%MOD;
inv_fact[i] = modinv(fact[i], MOD);
}
for(int i=0;i<=k;i++){
long long lcnt=m;
lcnt = (lcnt * nCr(n-1, i, MOD))%MOD;
lcnt = (lcnt * modpow(m-1, n-1-i, MOD))%MOD;
cnt = (cnt + lcnt)%MOD;
}
cout << cnt << endl;
}
| 0 |
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
while( n-- > 0 ){
int out = 0, score = 0, base = 0;
string event;
while( out < 3 ){
cin >> event;
if( event == "OUT" ) out++;
else if( event == "HIT" ){
score += base/3;
if( !(base/3) ) base++;
}else if( event == "HOMERUN" ){
score += base+1;
base = 0;
}
}
cout << score << endl;
}
return 0;
} | #include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(){
int n;
cin >> n;
for(int i=0;i<n;i++){
int p = 0;
int oc = 0;
int rui[4] = {1,0,0,0};
while(1){
string s;
getline(cin,s);
if(s=="OUT") oc++;
else if(s=="HIT"){
if(rui[3]==1) p++;
for(int j=3;j>0;j--) rui[j] = rui[j-1];
}
else if(s=="HOMERUN"){
for(int j=1;j<4;j++){
if(rui[j]==1) p++;
rui[j] = 0;
}
p++;
}
if(oc==3) break;
}
cout << p << endl;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
}
int mi = sum;
for (int i = 0; i < n; ++i) mi = min(mi, abs(sum - n * a[i]));
for (int i = 0; i < n; ++i) {
if (abs(sum - n * a[i]) == mi) {
cout << i << '\n';
return 0;
}
}
return 0;
}
| #include<cstdio>
#include<vector>
using namespace std;
int insSort(vector<int> &arr, int g) {
int v, cnt;
cnt = 0;
for(int i=g; i<arr.size(); ++i) {
int j;
v = arr[i];
for(j=i-g; j>=0 && arr[j]>v; j-=g) {
arr[j+g] = arr[j];
++cnt;
}
arr[j+g] = v;
}
return cnt;
}
int main() {
int n, tmp, m, cnt;
vector<int> arr, G;
scanf("%d", &n);
arr.reserve(n);
for(int i=0; i<n; ++i) {
scanf("%d", &tmp);
arr.push_back(tmp);
}
tmp = 4;
G.push_back(1);
for(m=1; tmp<n; ++m) {
G.push_back(tmp);
tmp = 3 * tmp + 1;
}
cnt = 0;
for(auto it=G.rbegin(); it!=G.rend(); ++it) {
cnt += insSort(arr, *it);
}
printf("%d\n", m);
for(auto it=G.rbegin(); it!=--(G.rend()); ++it) {
printf("%d ", *it);
}
printf("%d\n", G[0]);
printf("%d\n", cnt);
for(auto it=arr.begin(); it!=arr.end(); ++it) {
printf("%d\n", *it);
}
} | 0 |
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
const double PI=acos(-1.0);
typedef long long Int;
typedef long long LL;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef pair <double, double> PDD;
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 200007;
const int MAX2 = 1000007;
const int LEN = 21;
const int BASE = 1000000000;
const int MOD = 998244353;
int n;
int C[MAX];
int main()
{
cin >> n;
FOR (i,0,n)
{
int x;
scanf("%d", &x);
C[x] ++;
if (i == 0 && x != 0)
{
cout << 0 << endl;
return 0;
}
}
int tot = 1;
if (C[0] != 1)
{
cout << 0 << endl;
return 0;
}
Int res = 1;
FOR (i,1,n)
FOR (j,0,C[i])
res = res * C[i-1] % MOD;
cout << res << endl;
return 0;
}
| #include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
ll N;
ll a[200001];
ll ans = 0;
ll temparr[200001];
void mergesort(ll left, ll right){
if(right - left <= 1)
return;
ll mid = (left + right+1) / 2;
mergesort(left, mid);
mergesort(mid,right);
ll id1 = left;
ll id2 = mid;
ll cnt = 0;
for(ll i = left; i < right; i++){
if(id1 == mid){
temparr[i] = a[id2];
id2++;
}else if(id2 == right){
temparr[i] = a[id1];
id1++;
}else{
if(a[id1] < a[id2]){
temparr[i] = a[id1];
id1++;
}else{
temparr[i] = a[id2];
cnt += (mid - id1);
id2++;
}
}
}
for(ll i = left; i < right; i++){
a[i] = temparr[i];
}
// cout << left << ' ' << right << ' ' << cnt << endl;
ans += cnt;
}
int main(){
cin >> N;
for(ll i = 0; i < N; i++){
cin >> a[i];
}
mergesort(0, N);
cout << ans << endl;
} | 0 |
#include<iostream>
#include<cstdio>
#include<cstring>
namespace ShengXianTi
{
const int N=301000,MOD=1000000007;
inline void inc(int a,int &b){b=(a+b)%MOD;}
int f[N][2][3][3];
char s[N];
int n;
void dp()
{
s[n+1]='1',f[0][1][0][0]=1;
for(int p=0;p<=n;p++)
for(int r=0;r<2;r++)
for(int k=0;k<3;k++)
for(int sta=0;sta<3;sta++)
{
int v=f[p][r][k][sta];
if(s[p+1]=='?' || s[p+1]=='0')
{
if(k==0)inc(v,f[p+1][r][1][sta]);
else inc(v,f[p+1][r][k^3][sta]);
}
if(s[p+1]=='?' || s[p+1]=='1')
{
if(sta==2)
inc(v,f[p+1][r^(k!=1)][0][sta]);
else if(sta==1)
inc(v,f[p+1][r^(k!=1)][0][sta+(r==0 && k==0)]);
else if(sta==0)
inc(v,f[p+1][r^(k!=1)][0][sta+(r==1 && k==0)]);
}
}
}
void solve()
{
scanf("%s",s+1);
n=strlen(s+1);
dp();
int ans=0;
inc(f[n+1][0][0][2],ans);
inc(f[n+1][1][0][2],ans);
printf("%d\n",ans);
}
}
int main()
{
ShengXianTi::solve();
return 0;
}
| #include<iostream>
#include<vector>
using namespace std;
const int MOD=1000000007;
void add(long long &a,long long b){a+=b;if(a>=MOD)a-=MOD;}
int H,W,K;
long long solve(){
--K;
vector<vector<long long> > dp(H+1,vector<long long>(W,0));
dp[0][0]=1;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
for(int bit=0;bit<1<<(W-1);bit++){
bool ok=true;
for(int k=0;k<W-2;k++){
if((bit&(1<<k))&&(bit&(1<<(k+1)))) ok=false;
}
if(!ok)continue;
int nj=j;
if(bit&(1<<j))nj=j+1;
else if(j>0&&(bit&(1<<(j-1))))nj=j-1;
add(dp[i+1][nj],dp[i][j]);
}
}
}
return dp[H][K];
}
int main(){
while(cin>>H>>W>>K)cout<<solve()<<endl;
} | 0 |
#include <stdio.h>
#include <string.h>
int main(){
long long num;
scanf("%lld", &num);
char str[100] ={0};
int i = 0;
num--;
while(num >= 0){
str[i] = num%26 + 'a';
num /= 26;
i++;
num--;
}
int len = strlen(str);
for(int j=len-1;j>=0;j--){
printf("%c", str[j]);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
int nextInt() { int x; scanf("%d", &x); return x;}
const int MAX_N = 610;
int result1[MAX_N][MAX_N];
int result2[MAX_N][MAX_N];
void dfs(const int N, int r, int c, const vector<pair<int,int>>& d, int result[MAX_N][MAX_N], const int val) {
result[r][c] = val;
for (auto p : d) {
const int nr = r + p.first;
const int nc = c + p.second;
if (0 <= nr && nr < N && 0 <= nc && nc < N && result[nr][nc] == -1) {
dfs(N, nr, nc, d, result, 1-val);
}
}
}
void solve(int N, int D, int result[MAX_N][MAX_N]) {
vector<pair<int,int>> d;
REP(r, N) REP(c, N) {
if (r * r + c * c == D) {
d.push_back({r, c});
if (r > 0) d.push_back({-r, c});
if (c > 0) d.push_back({r, -c});
if (r > 0 && c > 0) d.push_back({-r, -c});
}
}
REP(r, N) REP(c, N) if (result[r][c] == -1) {
dfs(N, r, c, d, result, 0);
}
return;
}
int ans[MAX_N][MAX_N];
int main2() {
int N = nextInt();
int D1 = nextInt();
int D2 = nextInt();
CLR(result1, -1);
solve(2*N, D1, result1);
CLR(result2, -1);
solve(2*N, D2, result2);
vector<int> sz(4);
REP(r, 2*N) REP(c, 2*N) {
ans[r][c] = result1[r][c] * 2 + result2[r][c];
sz[ ans[r][c] ]++;
}
int cnt = 0;
int mai = distance(sz.begin(), max_element(ALL(sz)));
REP(r, 2*N) REP(c, 2*N) {
if (ans[r][c] == mai && cnt < N*N) {
printf("%d %d\n", r, c);
cnt++;
}
}
return 0;
}
int main() {
for (;!cin.eof();cin>>ws)
main2();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
int h,w;
cin >>h>>w;
VVi a(h,Vi(w,0));
int bef;
vector<pair<pair<int,int>,pair<int,int>>>ans;
rep(i,h){
rep(j,w){
cin>>bef;
a[i][j]+=bef;
if(a[i][j]%2){
if(j!=w-1){
ans.push_back(mp(mp(i,j),mp(i,j+1)));
a[i][j+1]++;
a[i][j]--;
}else if(i!=h-1){
ans.push_back(mp(mp(i, j), mp(i+1, j )));
a[i+1][j ]++;
a[i][j]--;
}
}
}
}
cout<<ans.size()<<endl;
rep(i,ans.size()){
printf("%d %d %d %d\n",1+ans[i].F.F,1+ans[i].F.S,1+ans[i].S.F,1+ans[i].S.S);
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;
char s[1000000];
ll t[3][1000001];
int main() {
int n, q;
scanf("%d%s%d", &n, s, &q);
V D, C;
rep(i, n) {
rep(j, 3) t[j][i+1] = t[j][i];
switch(s[i]){
case 'D':
++t[0][i+1];
D.push_back(i+1);
break;
case 'M':
++t[1][i+1];
break;
case 'C':
++t[2][i+1];
C.push_back(i);
break;
}
}
ll suma = 0, sumc = 0;
for (auto &a : D) suma += t[1][a] * t[2][a];
for (auto &c : C) sumc += t[1][c] * t[0][c];
rep(_, q) {
int k;
scanf("%d", &k);
ll ans = suma + sumc;
for (auto &a : D) ans -= t[1][a] * t[2][min(a+k-1, n)];
for (auto &c : C) ans -= t[1][c] * t[0][max(c-k+1, 0)];
printf("%lld\n", ans);
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
#define ll long long
const int N=2e5+9;
void slv()
{
int n;
cin>> n;
int a[n+3],b[n+3];
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++) cin >> b[i];
int l=0,r=n-1;
reverse(b,b+n);
for(int i=0;i<n;i++) {
if(a[i]==b[i]) {
if(b[l]!=b[i] && a[l]!=b[i]) {
swap(b[l],b[i]);
l++;
} else if(b[r]!=b[i] && a[r]!=b[i]) {
swap(b[r],b[i]);
r--;
} else {
puts("No");
return ;
}
}
}
for(int i=0;i<n;i++) {
if(a[i]==b[i]) {
puts("No");
return ;
}
}
puts("Yes");
for(int i=0;i<n;i++) cout<<b[i]<< " ";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t;
t=1;
int cs=1;
while (t--)
{
//cout<<"Case : "<<cs++<<endl;
slv();
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;
cin >> N;
vector <int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int ans = 0;
bool stop = false;
while (!stop) {
for (int i = 0; i < N; i++) {
if (A[i]%2==0) {
A[i] = A[i]/2;
} else {
stop = true;
break;
}
}
if (!stop) ans++;
}
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1000000000;
int main() {FIN
int t = 0;
char e;
vs nm = {"A", "B", "C"};
vs ply(3);
vi pos(3, 0);
cin >> ply[0];
cin >> ply[1];
cin >> ply[2];
while (true) {
if ((int)ply[t].size() == pos[t]) break;
e = ply[t][pos[t]];
pos[t]++;
t = (e - 'a');
}
cout << nm[t] << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main()
{
int n;
cin >> n;
string a, b, c;
cin >> a;
cin >> b;
cin >> c;
int count = 0;
rep(i, n) {
if(a[i] != b[i]) {
if(a[i] == c[i]) count++;
else if(b[i] == c[i]) count++;
else count += 2;
}
else {
if(a[i] != c[i]) count++;
}
}
cout << count << endl;
return 0;
} | 0 |
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
using int64 = uint64_t;
using namespace std;
vector<int64> prime_factor(int64 n) {
vector<int64> primes;
for (int64 i = 1; i * i <= n; i++) {
if (n % i == 0) {
primes.push_back(i);
if (n / i != i)
primes.push_back(n / i);
}
}
sort(primes.begin(), primes.end());
return primes;
}
int digits(int64 n) {
int cnt = 0;
while (n > 0) {
n /= 10;
cnt++;
}
return cnt;
}
int main() {
fastIO;
int64 n;
cin >> n;
vector<int64> primes = prime_factor(n);
int digit = 11;
int l = 0, r = (int)primes.size() - 1;
while (l <= r) {
if (primes.at(l) * primes.at(r) == n) {
int l_digit = digits(primes.at(l));
int r_digit = digits(primes.at(r));
digit = max(l_digit, r_digit);
r--;
} else {
l++;
}
}
cout << digit << endl;
}
| #include <iostream>
#include <cmath>
int main()
{
int64_t n;
std::cin >> n;
for (int64_t a = std::floor(std::sqrt(n)); a >= 1; --a)
{
if (n % a == 0)
{
const int64_t b = n / a;
std::cout << static_cast<int>(std::floor(std::log10(b) + 1)) << std::endl;
break;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(P a, P b)
{
return a.first < b.first;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int N;
ll M;
cin >> N >> M;
if(N==1)
{
cout << M << endl;
return 0;
}
ll ans=0;
vector<P> div;
for(ll i=2; i*i<=M; i++)
{
ll cnt = 0;
if(M%i==0)
{
cnt=M/i;
div.push_back(P(i, cnt));
div.push_back(P(cnt, i));
}
}
sort(div.begin(), div.end(), cmp);
reverse(div.begin(), div.end());
rep(i, div.size())
{
if(div[i].second>=N)
{
cout << div[i].first << endl;
return 0;
}
}
cout << 1 << endl;
return 0;
} | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int main()
{
cout << fixed << setprecision(10);
int N,M;
cin >> N >> M;
int n = M/N;
for(int i=n;i>0;i--)
{
if((M-(N-1)*i)%i==0)
{
cout << i << endl;
return 0;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int minimam(int a,int b,int c, int d);
int main() {
int a,b,c,d; cin >> a >> b >> c >> d;
int num;
num = minimam(a,b,c,d);
cout << num << endl;
return 0;
}
int minimam(int a,int b,int c, int d) {
return min(a,b)+min(c,d);
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
}return (N * jou(N, P-1)) % mod;} //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32; で小文字に
// cout << fixed << setprecision (20); 小数点以下20桁まで
//実行時間制約2秒では2×10^8回くらいまで計算できる
int main() {
int h,w,a,b;
cin >> h>>w>>a>>b;
rep(i,b){
rep(j,a) cout << 0;
rep(j,w-a) cout << 1;
cout << endl;
}
rep(i,h-b){
rep(j,a) cout << 1;
rep(j,w-a) cout << 0;
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r;cin>>r;
string ans;
if (r >= 2800) ans = "AGC";
else if (r >= 1200) ans = "ARC";
else ans = "ABC";
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
for (int i = N; i < 1000; i++) {
string s = to_string(i);
if (s[0] == s[1] && s[1] == s[2]) {
cout << i << endl;
return 0;
}
}
}
| 0 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define N 1000006
using namespace std;
int n, ans;
char s[N], t[N];
int main(){
scanf("%d%s%s", &n, s + 1, t + 1);
if(strcmp(s + 1, t + 1) == 0){
puts("0");
return 0;
}
int pos = n;
queue < int > Q;
for(int i = n; i; --i){
if(t[i] == t[i - 1]) continue;
pos = min(pos, i);
while(s[pos] != t[i] && pos) pos--;
if(!pos){
puts("-1");
return 0;
}
while(!Q.empty()){
int u = Q.front(), sz = Q.size();
if(u - sz + 1 > i) Q.pop();
else break;
}
Q.push(pos);
int sz = Q.size();
if(i != pos) ans = max(ans, sz);
}
cout << ans + 1 << endl;
return 0;
}
| #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
int n;
long long int m;
while (cin >> n >> m) {
if (n == 0 && m == 0) {
break;
}
long long int b;
vector<long long int> ss;
ss.push_back(0);
for (int i = 0; i < n; i++) {
cin >> b;
if (b <= m) {
ss.push_back(b);
}
}
vector<long long int> ss2;
for (long long int i = 0; i < ss.size(); i++) {
ss2.push_back(ss[i]);
for (long long int j = i; j < ss.size(); j++) {
if (ss[i]+ss[j] <= m) {
ss2.push_back(ss[i]+ss[j]);
}
}
}
sort(ss2.begin(), ss2.end());
/*for (long long int i = 0; i < ss2.size(); i++) {
cout << ss2[i] << endl;
}*/
long long int MAX = 0;
long long int sz = ss2.size();
for (long long int j = 0; j < sz; j++) {
long long int a = m;
for (long long int i = 0; i < 2; i++) {
vector<long long int>::iterator ite = upper_bound(ss2.begin(), ss2.end(), a);
if (ite != ss.begin()) {
ite--;
a -= *(ite);
}
}
vector<long long int>::iterator ite2 = ss2.end();
ss2.erase(ite2-1);
MAX = max(MAX, m-a);
}
cout << MAX << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll x, y;
cin >> x >> y;
ll absdif = abs(abs(x) - abs(y)), ans = 1e10;
if (x <= y) ans = min(ans, y - x); // 0,0
if (-1 * x <= y) ans = min(ans, y + x + 1); // 1,0
if (x <= -1 * y) ans = min(ans, -1 * y - x + 1); // 0,1
if (-1 * x <= -1 * y) ans = min(ans, -1 * y + x + 2); // 1,1
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
a=0;int d=1;char ch;
while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
a=ch^48;
while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
a*=d;
}
void read(ll &a)
{
a=0;int d=1;char ch;
while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
a=ch^48;
while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
a*=d;
}
int main()
{
int n,x,t;
read(n),read(x),read(t);
if(n%x==0) printf("%d\n",n/x*t);
else printf("%d\n",(n/x+1)*t);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
// 小数点以下桁数
// fixed << setprecision(i)
int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int64_t a){if(a<=1)return false;for(int64_t i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}
//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1); // v に 1, 2, ... N を設定
// do {
// for(auto x : v) cout << x << " "; cout << "\n"; // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) );
//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
// bitset<ビット数> s(tmp);
// // (ビット列sに対する処理)
// }
int main()
{
int n, k;
double ans, temp = 0;
cin >> n >> k;
vector<int64_t> p(n);
vector<double> a(n);
for (int i = 0; i < n; i++)
{
cin >> p[i];
a[i] = (double)sigma(1, p[i]) / p[i];
}
for (int i = 0; i < k; i++)
temp += a[i];
ans = temp;
for (int i = k; i < n; i++)
{
temp += a[i] - a[i - k];
ans = max(ans, temp);
}
cout << fixed << setprecision(6) << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll h,w;
cin >> h >> w;
vector<string> s(h);
for(auto &i:s)cin >> i;
vector<vector<ll>> dis(h,vector<ll>(w,1e9));
for(int i = 0;i<h;i++)
{
for(int j = 0;j<w;j++)
{
if(s[i][j]=='#')dis[i][j]=0;
}
}
for(int i = 0;i<h;i++)
{
for(int j = 1;j<w;j++)
{
dis[i][j] = min(dis[i][j],dis[i][j-1]+1);
}
}
for(int i = 0;i<h;i++)
{
for(int j = w-2;j>=0;j--)
{
dis[i][j] = min(dis[i][j],dis[i][j+1]+1);
}
}
for(int i = 1;i<h;i++)
{
for(int j = 0;j<w;j++)
{
dis[i][j] = min(dis[i][j],dis[i-1][j]+1);
}
}
for(int i = h-2;i>=0;i--)
{
for(int j = 0;j<w;j++)
{
dis[i][j] = min(dis[i][j],dis[i+1][j]+1);
}
}
ll ans = 0;
for(int i = 0;i<h;i++)for(int j = 0;j<w;j++)ans = max(ans,dis[i][j]);
cout << ans << endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
int n, k;
cin >> n >> k;
bool ans = n % k;
cout << ans << endl;
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (n%k==0) {
printf("0\n");
} else {
printf("1\n");
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using vl = vector<ll>;
int main() {
ll n;
cin >> n;
vl x(n);
rep(i, n) cin >> x[i];
ll l, q;
cin >> l >> q;
vector<vl> r(20, vl(n));
rep(i, n) r[0][i] = upper_bound(all(x), x[i] + l) - x.begin() - 1;
rep(k, 19) rep(i, n) r[k + 1][i] = r[k][r[k][i]];
rep(_, q) {
ll a, b;
cin >> a >> b;
if(a > b) swap(a, b);
a--;
b--;
ll ans = 1;
for(ll k = 19; k >= 0; k--)
if(r[k][a] < b) {
a = r[k][a];
ans += 1 << k;
}
cout << ans << '\n';
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, v;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
char d;
char ds[] = "NESW";
while(cin >> n, n) {
int rx = 10, ry = 10, cnt = 0;
int graph[21][21];
memset(graph, 0, sizeof(graph));
for(int i = 0, x, y; i < n; ++i) {
cin >> x >> y;
graph[y][x] = 1;
}
cin >> m;
for(int i = 0; i < m; ++i) {
cin >> d >> v;
for(int j = 0; j < 4; ++j) {
if(d == ds[j]) {
for(int k = 1; k <= v; ++k) {
rx += dx[j];
ry += dy[j];
if(graph[ry][rx] == 1) {
graph[ry][rx] = 0;
++cnt;
}
}
break;
}
}
}
cout << (cnt == n ? "Yes" : "No") << endl;
}
} | 0 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n;cin>>n;
string a,b,c;cin>>a>>b>>c;
int acc = 0;
for (int i=0;i<n;i++){
vector<char> letters;
letters.push_back(a[i]);
letters.push_back(b[i]);
letters.push_back(c[i]);
sort(letters.begin(), letters.end());
letters.erase(unique(letters.begin(), letters.end()), letters.end());
if (letters.size() == 2){
acc++;
} else if (letters.size() == 3){
acc += 2;
}
}
cout << acc << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;
const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(30) << setiosflags(ios::fixed);
int n;
cin >> n;
string s[3];
rep(i, 3) cin >> s[i];
int cnt = 0;
rep(i, n)
{
if (s[0][i] == s[1][i] && s[1][i] == s[2][i])
continue;
if (s[0][i] != s[1][i] && s[1][i] != s[2][i] && s[0][i] != s[2][i])
cnt += 2;
else
cnt++;
}
cout << cnt << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 200010;
int n, ans;
int read()
{
int x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * w;
}
inline void write(int x)
{
static int sta[35];
int top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top) putchar(sta[-- top] + 48);
}
signed main()
{
n = read();
ans = (n - 2) * 180;
write(ans);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
//MIN
main() {
int n;
cin >> n;
cout << 180*(n-2)<<endl;
}
| 1 |
#include<cstdio>
const int inf=1<<29;
int N,M;
int G[15][15],g[1<<15],f[1<<13][15];
void cmax(int&a,int b){b>a?a=b:1;}
int main(){
scanf("%d%d",&N,&M);
while(M--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
--a,--b;
G[a][b]=G[b][a]=c;
}
for(int S=1;S<1<<N;S++){
int i=N;while(!(S>>i&1))i--;
g[S]=g[S-(1<<i)];
for(int j=i;j--;)if(S>>j&1)g[S]+=G[i][j];
}
int ans=-inf;
for(int S=0;S<1<<N-2;S++){
for(int i=1;i<N;i++)if(S>>i-1&1){
int F=-inf;
for(int T=S;T;T=T-1&S)
if(T>>i-1&1)cmax(F,f[S-T][i]+g[T<<1]);
f[S][i]=F;
if(G[0][i])cmax(ans,F+g[(1<<N-1)-1-S*2]+G[0][i]);
}
for(int i=1;i<N;i++)if(!(S>>i-1&1)){
int F=-inf;
for(int j=1;j<N;j++)if((S>>j-1&1)&&G[i][j])cmax(F,f[S][j]+G[i][j]);
if(G[i][N-1])cmax(F,g[S<<1|1<<N-1]+G[i][N-1]);
f[S][i]=F;
}
if(G[0][N-1])cmax(ans,g[S<<1|1<<N-1]+g[(1<<N-1)-1-S*2]+G[0][N-1]);
}
printf("%d\n",g[(1<<N)-1]-ans);
} | #include <iostream>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
// for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}
template<int N>
struct sieve {
bool s[N];
constexpr sieve() : s() {
for (int i = 0; i < N; i++)
s[i] = true;
for (int i = 4; i < N; i += 2)
s[i] = false;
for (int i = 9; i < N; i += 6)
s[i] = false;
for (int i = 6, e = sqrt(N); i <= e; i += 6) {
for (int j : {i - 1, i + 1})
if (s[j])
for (int k = j * j; k < N; k += j)
s[k] = false;
}
}
};
template<int N>
struct twin {
int t[N/10], l;
constexpr twin() : t(), l(1) {
sieve<N> s;
t[0] = 5;
for (int i = 0; i < N; i++)
if (s.s[i - 2] && s.s[i])
t[l++] = i;
}
};
int main() {
enum {N = 10001};
twin<N> t;
for (int n; (n = in());) {
auto r = upper_bound(t.t, t.t + t.l, n) - 1;
outl(*r - 2, ' ', *r);
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge {
ll to; // 辺の行き先
ll weight; // 辺の重み
Edge(ll t, ll w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
int main() {
// 頂点数と辺数
ll n, m; cin >> n;
m = n - 1;
// グラフ入力受取 (ここでは重み付き無向グラフを想定)
Graph G(n);
for (ll i = 0; i < m; ++i) {
ll a, b, c;
cin >> a >> b >> c;
a--;
b--;
G[a].push_back(Edge(b, c));
G[b].push_back(Edge(a, c));
}
ll q, k; cin >> q >> k;
k--;
// BFS のためのデータ構造
vector<ll> dist(n, -1); // 全頂点を「未訪問」に初期化
queue<Edge> que;
// 初期条件 (頂点 k を初期ノードとする)
dist[k] = 0;
que.push(Edge(k, 0)); // 0 を橙色頂点にする
// BFS 開始 (キューが空になるまで探索を行う)
while (!que.empty()) {
Edge v = que.front(); // キューから先頭頂点を取り出す
que.pop();
// v から辿れる頂点をすべて調べる
for (Edge new_v : G[v.to]) {
if (dist[new_v.to] != -1) continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点 new_v について距離情報を更新してキューに追加する
dist[new_v.to] = dist[v.to] + new_v.weight;
que.push(new_v);
}
}
for (ll i = 0; i < q; i++) {
ll x, y; cin >> x >> y;
x--;
y--;
cout << dist[x] + dist[y] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }
int n, u, v;
vector< vector<int> > graphlist(100100, vector<int>());
vector<int> takahashi(100100, -1);
vector<int> aoki(100100, -1);
struct posdata {
int p; int dist;
};
int main() {
cin >> n >> u >> v;
u--; v--;
takahashi.at(u) = 0; aoki.at(v) = 0;
for(int i = 0; i < n-1; ++i) {
int aa, bb; cin >> aa >> bb;
aa--; bb--;
graphlist.at(aa).emplace_back(bb);
graphlist.at(bb).emplace_back(aa);
}
queue<posdata> tque;
posdata tfirst;
tfirst.p = u; tfirst.dist = 0;
tque.push(tfirst);
while(!tque.empty()) {
posdata now = tque.front();
tque.pop();
for(int i = 0; i < (int)graphlist.at(now.p).size(); ++i) {
int np = graphlist.at(now.p).at(i);
int ndist = now.dist+1;
if(takahashi.at(np) == -1) {
takahashi.at(np) = ndist;
posdata next;
next.p = np; next.dist = ndist;
tque.push(next);
}
}
}
queue<posdata> aque;
posdata afirst;
afirst.p = v; afirst.dist = 0;
aque.push(afirst);
while(!aque.empty()) {
posdata now = aque.front();
aque.pop();
for(int i = 0; i < (int)graphlist.at(now.p).size(); ++i) {
int np = graphlist.at(now.p).at(i);
int ndist = now.dist+1;
if(aoki.at(np) == -1) {
aoki.at(np) = ndist;
posdata next;
next.p = np; next.dist = ndist;
aque.push(next);
}
}
}
int amax = 0;
for(int i = 0; i < n; ++i) {
if(aoki.at(i) > takahashi.at(i)) {
chmax(amax, aoki.at(i));
}
}
cout << amax-1 << endl;
} | 0 |
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;
int ans = 100000000;
int main(){
int N; cin >> N;
vector<int> A(N,0);
rep(i,N) cin >> A[i];
vector<int> A2(N+2,0);
rep(i,N) A2[i+1] = A[i];
A2[N+1] = 0;
ll total = 0;
rep(i,N+1){
total += abs(A2[i] - A2[i+1]);
}
ll ans;
rep(i,N){
ans = total - abs(A2[i]-A2[i+1]) - abs(A2[i+1]-A2[i+2]) + abs(A2[i]-A2[i+2]);
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
vector<pair<T1, T2>> p;
rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
if (!isReverse) sort(p.begin(), p.end());
else sort(p.rbegin(), p.rend());
rep(i, f.size()) tie(f[i], s[i]) = p[i];
return;
}
int main(){
ll N; cin >> N;
vector<ll> a(N + 2, 0), s(N + 2, 0);
rep(i, N){
cin >> a[i + 1];
s[i + 1] = s[i] + abs(a[i] - a[i + 1]);
}
s[N + 1] = s[N] + abs(a[N] - a[N + 1]);
rep(i, N){
pt(s[i] + abs(a[i + 2] - a[i]) + s[N + 1] - s[i + 2]);
}
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void readin(T &x) {
x = 0;
T fh = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
x *= fh;
}
inline void d_read(double &x) {
x = 0.0;
int fh = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
if (ch == '.') {
double num = 1.0;
ch = getchar();
for (; isdigit(ch); ch = getchar()) x = x + (num /= 10) * (ch ^ 48);
}
x *= fh;
}
template <typename T>
inline void wt(T x) {
if (x > 9) wt(x / 10);
putchar(x % 10 + 48);
}
template <typename T>
inline void writeln(T x, char c) {
if (x < 0) {
putchar('-');
x = -x;
}
wt(x);
putchar(c);
}
const int N = 2e5 + 5;
int a[N << 2], t[N << 2], tg[N << 2];
inline void up(int p) {
a[p] = min(a[p << 1], a[p << 1 | 1]);
t[p] = min(t[p << 1], t[p << 1 | 1]);
}
inline void work(int p, int l, int r, int k) {
a[p] = k;
t[p] = k + l;
tg[p] = k;
}
inline void build(int p, int l, int r) {
tg[p] = -1e9;
if (l == r) {
a[p] = -l;
t[p] = a[p] + l;
}
else {
int mid = l + r >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
up(p);
}
}
inline void down(int p, int l, int r) {
if (tg[p] != -1e9) {
int mid = l + r >> 1;
a[p << 1] = a[p << 1 | 1] = tg[p];
tg[p << 1] = tg[p << 1 | 1] = tg[p];
t[p << 1] = tg[p] + l;
t[p << 1 | 1] = tg[p] + mid + 1;
tg[p] = -1e9;
}
}
int sum;
inline void ask(int p, int l, int r, int pos) {
if (l == pos && pos == r) {
sum = a[p];
}
else {
down(p, l, r);
int mid = l + r >> 1;
if (pos <= mid) ask(p << 1, l, mid, pos);
else ask(p << 1 | 1, mid + 1, r, pos);
}
}
inline void modify(int p, int l, int r, int ql, int qr, int k) {
if (l >= ql && r <= qr) {
a[p] = k;
t[p] = a[p] + l;
tg[p] = k;
}
else {
down(p, l, r);
int mid = l + r >> 1;
if (ql <= mid) modify(p << 1, l, mid, ql, qr, k);
if (mid < qr) modify(p << 1 | 1, mid + 1, r, ql, qr, k);
up(p);
}
}
int n, m;
int main() {
readin(n); readin(m);
int x, y;
build(1, 1, m);
for (int i = 1; i <= n; i ++) {
readin(x); readin(y);
sum = 1e8;
if (x > 1) ask(1, 1, m, x - 1);
modify(1, 1, m, x, y, sum);
if (t[1] + i >= 1e8) puts("-1");
else writeln(t[1] + i, '\n');
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// freopen("err.txt", "w", stderr);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int H, W;
cin >> H >> W;
map<int, int> S, freq;
for (int i = 0; i < W; i++) {
S[i] = i;
freq[0]++;
}
for (int i = 0; i < H; i++) {
int A, B;
cin >> A >> B;
--A; --B;
int mx = -1;
while (true) {
auto it = S.upper_bound(B);
if (it == S.begin()) break;
--it;
if (it->first < A) break;
mx = max(mx, it->second);
if (--freq[it->first - it->second] == 0) freq.erase(it->first - it->second);
S.erase(it);
}
if (mx != -1 && B + 1 != W) {
if (S.count(B + 1)) {
if (--freq[B + 1 - S[B + 1]] == 0) freq.erase(B + 1 - S[B + 1]);
S[B + 1] = max(S[B + 1], mx);
} else S[B + 1] = mx;
freq[B + 1 - S[B + 1]]++;
}
if (freq.empty()) cout << -1 << nl;
else cout << (i + 1) + freq.begin()->first << nl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,A,B;
cin>>N;
if(N==1){
cout<<"Hello World";
}
if(N==2){
cin>>A>>B;
cout<<A+B;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll x; cin >> x;
ll ans = 0;
ll quo = x / 11;
ll mod = x % 11;
if (mod == 0) {
ans = quo * 2;
}
else if (1 <= mod && mod <= 6) {
ans = quo * 2 + 1;
}
else { // 6 < mod <= 11
ans = quo * 2 + 2;
}
cout << ans << endl;
return 0;
} | 0 |
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;
static const int sentinel = 1000000000;
long int ninvention = 0;
int merge(int A[], int left, int mid, int right) {
int n1 = mid - left;
int n2 = right - mid;
int L[n1 + 1], R[n2 + 1];
for (int i = 0; i < n1; i++)
L[i] = A[left + i];
for (int i = 0; i < n2; i++)
R[i] = A[mid + i];
L[n1] = sentinel;
R[n2] = sentinel;
int i = 0, j = 0;
for (int k = left; k < right; k++) {
if (L[i] <= R[j]) {
A[k] = L[i];
i++;
} else {
ninvention += max(0, n1 - i);
A[k] = R[j];
j++;
}
}
}
int mergeSort(int A[], int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
mergeSort(A, left, mid);
mergeSort(A, mid, right);
merge(A, left, mid, right);
}
}
int main() {
int data[MAX];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> data[i];
}
mergeSort(data, 0, n);
cout << ninvention << endl;
} | #include <iostream>
#include <math.h>
using namespace std;
int main(){
int in;
cin >> in;
int out = static_cast<int>(pow(static_cast<double>(in), 3.0));
cout << out << endl;
return 0;
} | 0 |