code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include<cstdio>
const int N=1e5+9;
int L[17][N],R[17][N],n,t,q,X[N],ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",X+i);
scanf("%d",&t);
for(int i=1,it=1;i<=n;++i){
while(it<n&&X[it+1]-X[i]<=t)++it;
R[0][i]=it;
}
for(int i=n,it=n;i;--i){
while(it>1&&X[i]-X[it-1]<=t)--it;
L[0][i]=it;
}
for(int i=1;i<17;++i)
for(int j=1;j<=n;++j)
R[i][j]=R[i-1][R[i-1][j]],L[i][j]=L[i-1][L[i-1][j]];
for(scanf("%d",&q);q--;printf("%d\n",ans)){
int x,y;ans=1;
scanf("%d%d",&x,&y);
if(x<=y){
for(int i=16;~i;--i)
if(R[i][x]<y)ans+=1<<i,x=R[i][x];
}else{
for(int i=16;~i;--i)
if(L[i][x]>y)ans+=1<<i,x=L[i][x];
}
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
while(cin>>n>>k,n||k) {
int cost[n][n]; FOR(i,0,n) FOR(j,0,n) cost[i][j] = 1e9;
FOR(i,0,k) {
int x; cin >> x;
if(x == 0) {
int d[n]; FOR(i,0,n) d[i] = 1e9;
bool used[n]; CLR(used);
// ??????????????????
int a, b; cin >> a >> b;
a--;b--;
d[a] = 0;
while(1) {
int v = -1;
for(int u = 0; u < n; u++) {
if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
}
if(v == -1) break;
used[v] = true;
for(int u = 0; u < n; u++) {
d[u] = min(d[u], d[v] + cost[v][u]);
}
}
if(d[b] >= 1e9) d[b] = -1;
cout << d[b] << endl;
} else {
int c, d, e; cin >> c >> d >> e;
c--;d--;
cost[c][d] = min(cost[c][d], e);
cost[d][c] = min(cost[d][c], e);
}
}
}
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
//#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 200005 //check the limits, man
const ll INF = 1e12;
int par[N],lev[N],tot[N];
void makeset(int n)
{
fill(par,par+n,-1);
fill(lev,lev+n,0);
fill(tot,tot+n,1);
return;
}
int findset(int x)
{
int y=x;
while(par[y]>=0)
y=par[y];
if(x!=y)
par[x]=y;
return y;
}
void combine(int a,int b)
{
a=findset(a);
b=findset(b);
if(a!=b)
{
if(lev[a]<lev[b])
par[a]=b,tot[b]+=tot[a];
else if(lev[a]>lev[b])
par[b]=a,tot[a]+=tot[b];
else
lev[b]++,par[a]=b,tot[b]+=tot[a];
}
return ;
}
vvi ad(N);
int ar[N];
bool vis[N];
int K;
void dfs(int s)
{
int i,a,x=ad[s].size();
vis[s]=1;
ar[K++]=s;
rep(i,x)
{
a=ad[s][i];
if(!vis[a])
dfs(a);
}
}
int main()
{
int n,x,y,i,j,a,b;
in(n);
in2(x,y);
while(x--)
{
in2(a,b);
a--,b--;
ad[a].pb(b);
ad[b].pb(a);
}
makeset(n);
while(y--)
{
in2(a,b);
combine(a-1,b-1);
}
vi v(n);
vii temp;
rep(i,n)
{
if(!vis[i])
{
K=0;
dfs(i);
temp.clear();
rep(j,K)
{
a=ar[j];
b=findset(a);
temp.pb(b,a);
}
sort(all(temp));
j=0;
while(j<K)
{
a=j;
while(a<K && temp[j].F==temp[a].F)
a++;
lp(b,j,a)
v[temp[b].S]=a-j;
j=a;
}
}
}
dbg(v,i,n);
}
| #include <bits/stdc++.h>
using namespace std;
const int N=200005;
int f1[N],f2[N];
map <pair <int ,int > ,int > ans;
inline int getrt(int x,int *f){
return f[x]==x?x:f[x]=getrt(f[x],f);
}
inline void merge(int x,int y,int*f){
if (getrt(x,f)!=getrt(y,f))
f[getrt(x,f)]=y;
}
int main (){
int n,m,k;scanf ("%d%d%d",&n,&m,&k);
for (int i=1;i<=n;i++) f1[i]=f2[i]=i;
for (int i=1,u,v;i<=m;i++)
scanf ("%d%d",&u,&v),merge(u,v,f1);
for (int i=1,u,v;i<=k;i++)
scanf ("%d%d",&u,&v),merge(u,v,f2);
for (int i=1;i<=n;i++)
ans[make_pair(getrt(i,f1),getrt(i,f2))]++;
for (int i=1;i<=n;i++)
printf ("%d ",ans[make_pair(getrt(i,f1),getrt(i,f2))]);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
ll ans = 1;
for (int i = 0; i < B; i++) {
ans *= A - i;
}
for (int i = 0; i < B; i++) {
ans /= i + 1;
}
return ans;
}
int main() {
int N;
cin>>N;
int P=N;
int S;
bool a=true;
while(a==true){
if(N==0){
a=false;
}
else{
S+=N%10;
N-=N%10;
N/=10;
}
}
if(P%S==0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
| //高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
int main() {
ll ans = 0;
ll tmp = 0;
ll n;
cin >> n;
string s = "";
if(n==0) cout << 0 << endl;
else {
while(tmp != n){
//cout << s.size() << " " << tmp << " " << s << endl;
if(abs(n-tmp)%((ll)1<<(s.size()+1))==0) s = "0" + s;
else {
tmp += (ll)pow(-1, s.size()) * ((ll)1<<s.size());
s = "1" + s;
}
}
cout << s << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
int main(){
int n;
string st = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
cin >>n;
while(n!=0){
string s;
vector<int>key;
string ans = "";
for(int i = 0; i<n;i++){
int x;
cin >>x;
key.push_back(x);
}
cin >>s;
int ind = 0;
for (int i = 0; i<(int)s.size(); i++){
char c;
for (int j = 0; j < (int)st.size();j++){
if(s[i] == st[j]){
if(j - key[ind] < 0)c = st[j - key[ind] + 52];
else c = st[j - key[ind]];
}
}
ans = ans + c;
ind++;
if(ind >= (int)key.size()){
ind = 0;
}
}
cout <<ans<<endl;
key.clear();
cin >>n;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 9;
int l[N], r[N];
int main(){
fastIO;
int n;
cin >> n;
int lmx = 0, rmn = (int)1e9 + 1;
for(int i = 0 ; i < n; i ++ ){
cin >> l[i] >> r[i];
lmx = max(lmx, l[i]);
rmn = min(rmn, r[i]);
}
vector<pii> shits;
for(int i = 0 ; i < n; i ++ ){
shits.push_back(mp(rmn - l[i] + 1,r[i] - lmx + 1));
}
sort(shits.begin(), shits.end());
int low = (int)1e9 + 1;
int ans = 0;
for(int i = 0 ; i < n; i ++ ){
ans = max(ans, (r[i] - l[i] + 1) + max(rmn-lmx+1,0));
}
for(int i = 0 ; i + 1 < n; i ++ ){
low = min(low, shits[i].se);
ans = max(ans, max(0,low) + max(0,shits[i + 1].fi));
}
ans = max(ans, max(0,shits[0].fi) + max(0,shits[n-1].fi));
cout << ans << "\n";
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}
inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
int main()
{
int N, Q;
while (N = in(), Q = in(), N || Q){
int bkt[128] = {};
for (int i = 0; i < N; i++){
for (int x = in(); x--;){
bkt[in()]++;
}
}
int maxi = 0;
for (int i = 1; i < 128; i++){
if (bkt[i] >= Q && bkt[maxi] < bkt[i]){
maxi = i;
}
}
cout << maxi << endl;
}
return 0;
} | //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
while(true){
int N, M; cin >> N >> M;
if(N == M && M == 0) break;
int day[101], mx = 0;
fill(day, day+101, 0);
REP(i,N){
int m, d;
cin >> m;
REP(j,m){
cin >> d;
mx = max(mx, ++day[d]);
}
}
if(mx < M) cout << 0 << endl;
else{
REP(i,101)
if(day[i] == mx){
cout << i << endl;
break;
}
}
}
return 0;
} | 1 |
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int w[10], k[10];
for(int i = 0;i < 10;i++)scanf("%d",w + i);
for(int i = 0;i < 10;i++)scanf("%d",k + i);
sort(w,w + 10);
sort(k,k + 10);
printf("%d %d\n",w[9] + w[8] + w[7], k[9] + k[8] + k[7]);
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
int wc[10], wsum=0, kc[10], ksum=0;
for(int i = 0 ; i < 10 ; i++) {
cin >> wc[i];
}
for(int i = 0 ; i < 10 ; i++) {
cin >> kc[i];
}
sort(wc, wc+10);
sort(kc, kc+10);
for(int i = 9 ; i > 6 ; i--) {
wsum += wc[i];
ksum += kc[i];
}
cout << wsum << ' ' << ksum << endl;
return 0;
} | 1 |
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll gcd(ll a,ll b){
if(b == 0) return a;
return gcd(b , a % b);
}
const ll MOD = 1000000007;
const ll MAX = 2000001;
ll mod(ll a){
return a % MOD;
}
ll lcm(ll a,ll b){
return (a*b)/gcd(a,b);
}
ll fac[MAX], finv[MAX], inv[MAX];
void nCrprep() {
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 nCr(ll n, ll r){
if (n < r) return 0;
if (n < 0 || r < 0) return 0;
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
ll nCrcheep(ll n,ll r){
if(r == 0) return 1;
else if(r == 1) return n;
else return nCrcheep(n-1,r-1)*n/r;
}
vector<pair<ll,ll>> prime_factorize(ll n){
vector<pair<ll,ll>> res;
for(ll i=2; i*i <= n; i++){
if(n % i != 0) continue;
ll ex = 0;
while(n % i == 0){
ex++;
n /= i;
}
res.push_back({i,ex});
}
if(n != 1) res.push_back({n,1});
return res;
}
int main(){
ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e;
ll mintime = min({a,b,c,d,e});
cout << 4 + (n + mintime-1)/mintime << endl;
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//ceil(n/m)
int int_ceil(int n, int m)
{
if (n % m == 0) return n / m;
return n / m + 1;
}
signed main()
{
int N;
int A[5];
cin >> N;
REP(i, 5) cin >> A[i];
int cur = N;
for (int i = 0; i < 5; i++)
{
cur = min(cur, A[i]);
}
int n = int_ceil(N, cur);
cout << n + 4 << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50
ll gcd(ll a, ll b)
{
if(b == 0)
{
return a;
}
return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
ll g = gcd(a, b);
return a/g * b; //prevent overflow
}
///////////////////////// END OF TEMPLATE /////////////////////////////////////////
vp adj[100001];
bool visited[100001];
vll dist(100001);
void dfs(int k)
{
visited[k] = 1;
for(auto u : adj[k])
{
if(!visited[u.first])
{
dist[u.first] = dist[k] + u.second;
dfs(u.first);
}
}
}
int main()
{
int n;
cin >> n;
for(int i = 0; i < n-1; ++i)
{
int a, b, c;
cin >> a >> b >> c;
adj[a].pb({b, c});
adj[b].pb({a, c});
}
int q, k;
cin >> q >> k;
dfs(k);
while(q--)
{
int x, y;
cin >> x >> y;
cout << dist[x] + dist[y] << endl;
}
} | #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
struct edge{
ll to, cost;
};
int main()
{
ll N;
cin >> N;
vector<vector<ll>> A(N-1,vector<ll>(3));
vector<vector<edge>> vec(N,vector<edge> ());
REP(i, N-1){
REP(j, 3){
cin >> A.at(i).at(j);
}
A.at(i).at(0)--;
A.at(i).at(1)--;
edge e1 = {A.at(i).at(1),A.at(i).at(2)};
edge e2 = {A.at(i).at(0),A.at(i).at(2)};
vec.at(A.at(i).at(0)).push_back(e1);
vec.at(A.at(i).at(1)).push_back(e2);
}
ll Q,K;
cin >> Q >> K;
K--;
queue<ll> que;
vector<ll> dist(N,-1);
que.push(K);
dist[K]=0;
while(!que.empty()){
ll v = que.front();
que.pop();
for(auto e:vec.at(v)){
ll nv = e.to;
ll ncost = e.cost;
if(dist[nv]!=-1) continue;
dist[nv]=dist[v]+ncost;
que.push(nv);
}
}
vector<ll> ans(Q);
REP(i,Q){
ll x,y;
cin >> x >> y;
x--;
y--;
ans.at(i)=dist[x]+dist[y];
}
REP(i,Q){
cout << ans.at(i) << endl;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s,a;
cin>>s;
set<char> t(all(s));
a = "abcdefghijklmnopqrstuvwxyz";
for (auto c:a)
{
auto pos =t.find(c);
if(pos==t.end()){
cout<<c;
return 0;
}
}
cout<<"None";
return 0;
} | #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60) //1LL<<63でオーバーフロー
#define inf (1<<29) //1<<29でオーバーフロー
int main(int argc,char* argv[]){
string s;
cin >> s;
set<char> c;
for(int i=0;i<26;i++){
c.insert((char)('a'+i));
}
bool ans=true;
for(int i=0;i<s.size();i++){
if(c.count(s[i]))c.erase(s[i]);
if(c.empty())ans=false;
}
if(ans){
auto it = c.begin();
cout << *it << endl;
}
else cout << "None" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int l[200000] = {0};
int main() {
int N;
map<int, int> d;
scanf("%d", &N);
for(int i=0;i<N;i++) {
scanf("%d", &l[i]);
}
for(int i=0;i<N;i++) {
auto itr = d.find(l[i]);
if(itr != d.end()) {
d[l[i]]++;
}
else {
d[l[i]] = 1;
}
}
int ans = 0;
for(auto i=d.rbegin();i!=d.rend();i++) {
while(i->second > 0) {
int isFinished = 0;
for(int j=0;j<32;j++) {
int v = pow(2, j) - i->first;
if (i->first < v) {
break;
}
if (d.find(v)!=d.end()) {
if ((v!=i->first && d[v]>=1) || (v==i->first && d[v]>=2)) {
i->second--;
d[v]--;
ans++;
isFinished = 1;
break;
}
}
}
if(isFinished==0) {
break;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
int n;
cin >> n;
vector<ll> A(n);
rep(i, n) cin >> A[i];
unordered_map<ll, int> c;
rep(i, n) c[A[i]] = 0;
rep(i, n) c[A[i]]++;
int sum = 0;
for (auto kv: c) {
if (kv.second % 2 == 1)
sum++;
}
put(sum);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,s,n) for(int i=s;i<n;++i)
#define FORR(i,s,n) for(int i=n-1;i>=s;--i)
#define ALL(c) (c).begin(),(c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define ABS(a) ((a)>0?(a):-(a))
#define F first
#define S second
ll n, v[100000];
P a[100001], b[100001];
int main(int argc, char **argv) {
cin >> n;
REP(i, n) cin >> v[i];
REP(i, 100001) a[i] = b[i] = P{0, i};
REP(i, n/2) ++a[v[i*2]].F;
REP(i, n/2) ++b[v[i*2+1]].F;
sort(a, a+100001); reverse(a, a+100001);
sort(b, b+100001); reverse(b, b+100001);
if (a[0].S == b[0].S) cout << min(n - a[0].F - b[1].F, n - b[0].F - a[1].F) << endl;
else cout << (n - a[0].F - b[0].F) << endl;
return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
int n, tmp;
cin >> n;
map<int, int> odd, even;
rep(i, n) {
cin >> tmp;
if (i % 2 == 0) even[tmp]++;
else odd[tmp]++;
}
P oddMax, evenMax;
oddMax = make_pair(-1, -1);
evenMax = make_pair(-1, -1);
int oddOthers, evenOthers;
oddOthers = evenOthers = 0;
for (auto a : odd) {
if (oddMax.second < a.second) oddMax = a;
}
for (auto a : even) {
if (evenMax.second < a.second) evenMax = a;
}
int ans = iINF;
if (oddMax.first == evenMax.first) {
int tmpAns = 0;
int tmpOdd, tmpEven;
tmpOdd = tmpEven = 0;
for (auto a : odd) {
if (a.first == oddMax.first) continue;
tmpOdd += a.second;
}
for (auto a : even) {
if (a.first == evenMax.first) continue;
tmpEven += a.second;
}
tmpAns = tmpOdd;
P tmpEvenMax = make_pair(-1, -1);
for (auto a : even) {
if (a.first == evenMax.first) continue;
if (tmpEvenMax.second < a.second) tmpEvenMax = a;
}
int tmptmpEven = 0;
for (auto a : even) {
if (a.first == tmpEvenMax.first) continue;
tmptmpEven += a.second;
}
tmpAns += tmptmpEven;
ans = min(ans, tmpAns);
tmpAns = tmpEven;
P tmpOddMax = make_pair(-1, -1);
for (auto a : odd) {
if (a.first == oddMax.first) continue;
if (tmpOddMax.second < a.second) tmpOddMax = a;
}
int tmptmpOdd = 0;
for (auto a : odd) {
if (a.first == tmpOddMax.first) continue;
tmptmpOdd += a.second;
}
tmpAns += tmptmpOdd;
ans = min(ans, tmpAns);
}
else {
ans = 0;
for (auto a : odd) {
if (a.first == oddMax.first) continue;
ans += a.second;
}
for (auto a : even) {
if (a.first == evenMax.first) continue;
ans += a.second;
}
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
int N,L;
cin>>N>>L;
int data[N];
int m=1000,sum=0;
rep(i,N){
data[i]=L+i;
m=min(m,abs(data[i]));
sum+=data[i];
}
bool exist=false;
rep(i,N){
if(m==data[i]){
exist=true;
break;
}
}
int ans;
if(exist==true){
ans=sum-m;
}
else{
ans=sum+m;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n)
{
// Corner cases
if (n <= 1)
return 1;
if (n <= 3)
return 2;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return 1;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return 1;
return 2;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007;
return res; }
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
ll findlcm(ll arr[], int n)
{
ll ans = arr[0];
for (int i = 1; i < n; i++)
ans = (((arr[i] * ans)) /
(gcd(arr[i], ans)));
return ans;
}
int main()
{
fast;
ll t=1;
//cin>>t;
while(t--)
{
ll n,l;
cin>>n>>l;
ll k=l-1;
ll sum=((n*(n+1))/2)+n*k;
//cout<<sum<<" ";
for(ll i=1;i<=n;i++)
{
if(i==-k)
{
cout<<sum;
exit(0);
}
}
if(k>=0)
{
cout<<sum-k-1;
}
else
{
cout<<sum-n-k;
}
}
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define N 1001000
#define inf INT_MAX
inline int read()
{
int s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
int n;
char a[N],b[N];
int pos[N],Ans,cnt,ans[N];
bool Chtholly=true;
int main()
{
//freopen("game.in","r",stdin);
//freopen("game.out","w",stdout);
n=read();
scanf("%s%s",a+1,b+1);
int len=1;
//while(a[len]==b[len])
//for(int i=1;i<=n+10;i++) cout<<a[i]<<endl;
while(a[len]==b[len]&&len<=n) len++;
if(len==n+1) return puts("0"),0;
int front=n+1,rear=n;
int k=n+1;
while(n)
{
int j=n;
while(b[j-1]==b[n]&&j>=1) j--;
k=min(k,j);
while(a[k]!=b[n]&&k>=1) k--;
if(!k) {Chtholly=false;break;}
while(front<=rear&&pos[rear]-cnt>n) rear--;
cnt++;
front--;
pos[front]=k+cnt;
ans[front]=cnt;
Ans=max(Ans,cnt-ans[rear]+1);
n=j-1;
}
if(!Chtholly) {puts("-1");return 0;}
printf("%d\n",Ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=1e9+7;
int main(){
int K,T; cin >> K >> T;
int a[T];
for(int i=0;i<T;i++){
cin >> a[i];
}
sort(a,a+T);
int sum=0;
for(int i=0;i<T-1;i++){
sum+=a[i];
}
int ans=max(a[T-1]-1-sum,0);
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//c
int main(){
int n, k;cin >> n >> k;
vector<vector<int>> a(51, vector<int>(n));
rep(i, n) cin >> a[0][i];
rep(i, k){
vector<int> memo(n+1);
rep(j, n){
int min, max;
min=j-a[i][j];
max=j+1+a[i][j];
if(min<0) min=0;
if(max>n) max=n;
memo[min]++;
memo[max]--;
}
int cnt=0;
rep(j, n){
cnt+=memo[j];
a[i+1][j]=cnt;
}
bool fin=true;
rep(j, n){
if(a[i][j]!=a[i+1][j]) fin=false;
}
if(fin){
k=i+1;
break;
}
}
rep(j, n-1){
cout << a[k][j] << " ";
}
cout << a[k][n-1] << endl;
return 0;
} | #include <cstdio>
#include <algorithm>
using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;
i32 a[200000];
auto main() -> i32 {
i32 n, k;
scanf("%d%d", &n, &k);
for (i32 i = 0; i < n; i += 1) {
scanf("%d", a + i);
}
i32 b[200001];
for (i32 step = 0; step < std::min(64, k); step += 1) {
std::fill(b, b + n + 1, 0);
for (i32 i = 0; i < n; i += 1) {
b[std::max(0, i - a[i])] += 1;
b[std::min(n, i + a[i] + 1)] -= 1;
}
a[0] = b[0];
for (i32 i = 1; i < n; i += 1) {
b[i] += b[i - 1];
a[i] = b[i];
}
}
for (i32 i = 0; i < n; i += 1) {
printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
}
return 0;
}
| 1 |
#ifndef _WIN32
#include<iostream>
#endif
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define FOR(i,bg,ed) for(int i = (bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
}star;
template<typename T>
istream & operator>> (istream &is, vector<T>&v) {
for (auto &it : v)is>> it;
return is;
}
char f(char c) {
if (c == 'a')return 'Z';
if (c == 'A')return 'z';
return c - 1;
}
int main() {
int n;
while (cin >> n, n) {
vector<int> k(n);
cin >> k;
string s;
cin >> s;
int id = 0;
for (auto &c : s) {
REP(i,k[id]) {
c = f(c);
}
id++;
id %= n;
}
cout << s << endl;
}
return 0;
} | #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<functional>
#include<climits>
using namespace std;
typedef pair<int,int>pii;
const int INF=1e9;
const int dx[]={0,-1,0,1},dy[]={-1,0,1,0};
int main(){
int n;
while(cin>>n,n){
int a[100];for(int i=0;i<n;i++)cin>>a[i];
char str[128];cin>>str;
for(int i=0;str[i];i++){
int val=(isupper(str[i])?tolower(str[i])-'a'+26:str[i]-'a');
int next=val-a[i%n];
next=(next+52)%52;
if(next>25)next=toupper('a'+next-26)-'a';
printf("%c",'a'+next);
}
puts("");
}
return 0;
} | 1 |
#include <cstdio>
#include <cstring>
const int mod = 1e9 + 7;
const int MAXN = 3e5 + 5;
template<typename _T>
void read( _T &x )
{
x = 0;char s = getchar();int f = 1;
while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
x *= f;
}
template<typename _T>
void write( _T x )
{
if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
if( 9 < x ){ write( x / 10 ); }
putchar( x % 10 + '0' );
}
template<typename _T>
_T MIN( const _T a, const _T b )
{
return a < b ? a : b;
}
int f[MAXN][3][3];
char S[MAXN];
int N;
int add( int &x, const int y ) { return x = ( x + y >= mod ? x + y - mod : x + y ); }
int main()
{
scanf( "%s", S + 1 );
f[0][0][0] = 1, N = strlen( S + 1 );
for( int i = 0 ; i < N ; i ++ )
for( int j = 0 ; j < 3 ; j ++ )
for( int k = 0 ; k < 3 ; k ++ )
if( f[i][j][k] )
{
if( S[i + 1] ^ '1' ) add( f[i + 1][j][k == 2 ? 1 : k + 1], f[i][j][k] );
if( S[i + 1] ^ '0' )
{
if( k ) add( f[i + 1][j][k - 1], f[i][j][k] );
else add( f[i + 1][MIN( j + 1, 2 )][k], f[i][j][k] );
}
}
write( add( f[N][1][0], add( f[N][2][0], add( f[N][2][1], f[N][2][2] ) ) ) ), putchar( '\n' );
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N=300005,M=1e9+7;
char s[N];
int t[8][2],f[N][8];
int main(){
t[0][0]=2;t[0][1]=1;t[1][0]=3;t[1][1]=5;
t[2][0]=4;t[2][1]=7;t[3][0]=6;t[3][1]=1;
t[4][0]=2;t[4][1]=2;t[5][0]=5;t[5][1]=5;
t[6][0]=3;t[6][1]=3;t[7][0]=2;t[7][1]=1;
scanf("%s",s);
int n=strlen(s);
f[n][1]=1;
f[n][5]=1;
for (int i=n-1;i>=0;i--)
for (int j=0;j<8;j++){
if (s[i]!='1')f[i][j]+=f[i+1][t[j][0]];
if (s[i]!='0')f[i][j]+=f[i+1][t[j][1]];
f[i][j]%=M;
}
printf("%d\n",f[0][0]);
} | 1 |
#include <iostream>
int main(){
int a, b, x, i, n;
long long int s = 0;
a=-1000000;//MAX
b=1000000;//min
std::cin >> n;
for(i=0;i<n;i++){
std::cin >> x;
s += x;
if(x > a) a = x;
if(x < b) b = x;
}
std::cout << b << " " << a << " " << s << std::endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> a(2);
int k;
cin >> a[0] >> a[1] >> k;
int times = 0;
int side = 0;
while(1){
if(a[side] % 2 == 1) a[side] -= 1;
a[side] /= 2;
a[(side+1)%2] += a[side];
side += 1;
side %= 2;
times += 1;
if(times == k) break;
}
cout << a[0] << " " << a[1] << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");
int main(){
IO_STREAM;
int n; cin>>n;
vector<pair<int,int>>odd(100000);
vector<pair<int,int>>even(100000);
set<int>kind;
rep(i,0,n){
int v;
cin>>v;
kind.insert(v);
if(i%2==0){
even[v].first++;
even[v].second=v;
}
else{
odd[v].first++;
odd[v].second=v;
}
}
sort(all(even));
reverse(all(even));
sort(all(odd));
reverse(all(odd));
int ans;
if(kind.size()==1){
ans=n/2;
}
else{
ans=100000;
if(odd[0].second!=even[0].second) ans=min(ans,n-odd[0].first-even[0].first);
if(odd[0].second!=even[1].second) ans=min(ans,n-odd[0].first-even[1].first);
if(odd[1].second!=even[0].second) ans=min(ans,n-odd[1].first-even[0].first);
if(odd[1].second!=even[1].second) ans=min(ans,n-odd[1].first-even[1].first);
}
cout<<ans<<endl;
return 0;
}
| #include "bits/stdc++.h"
#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define For(i,a,n) for(i=a;i<n;i++)
#define all(ar) ar.begin(),ar.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;
const ll mod = 1000000007;
bool cmp(pair<int,int> a,pair<int,int> b){
return a.S > b.S;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
/*
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
//*/
ll i,n;
cin>>n;
ll ar[n];
For(i,0,n) cin>>ar[i];
map<ll,ll> oc0, oc1;
pair<ll,ll> mx10 = {-1,0},mx11 = {-1,0},mx20 = {-1,0},mx21 = {-1,0};
for(ll a = 0; a < n;a += 2){
oc0[ar[a]] += 1;
}
for(ll a = 1; a < n;a += 2){
oc1[ar[a]] += 1;
}
vector<pair<ll,ll> > vec0,vec1;
for(auto itr = oc0.begin(); itr != oc0.end(); ++itr){
vec0.pb(*itr);
}
for(auto itr = oc1.begin(); itr != oc1.end(); ++itr){
vec1.pb(*itr);
}
sort(vec0.begin(),vec0.end(),cmp);
sort(vec1.begin(),vec1.end(),cmp);
mx10 = vec0[0];
mx11 = vec1[0];
if(vec0.size()>1) mx20 = vec0[1];
if(vec1.size()>1) mx21 = vec1[1];
//for(auto k: vec0) cout<<k.F sp<<k.S el;
//for(auto k: vec1) cout<<k.F sp<<k.S el;
if(mx11.F != mx10.F){
int a = mx10.S, b = mx11.S;
cout<<n - (a + b);
}
else{
int x;
x = max((mx10.S + mx21.S),(mx11.S + mx20.S));
cout<< n - x;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define maxn 100010
#define ll long long
using namespace std;
int n,m,vis[maxn];
ll ans[maxn],a[maxn],k,cnt,q[maxn],pos[maxn];
template <class T>
void read(T &x){
char s=getchar();int f=0;x=0;
while(s<'0'||s>'9'){if(s=='-') f=1;s=getchar();}
while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=getchar();
x=f?-x:x;
}
int main(){
read(n);
for(int i=1;i<=n;i++){
read(a[i]);
pos[i]=1ll*i;
}
read(m);read(k);
for(int i=n;i>=1;i--) a[i]=a[i]-a[i-1];
for(int i=1,x;i<=m;i++){
read(x);
swap(pos[x],pos[x+1]);
}
for(int i=1;i<=n;i++){
ll p=i;cnt=0;
if(vis[i]) continue;
q[++cnt]=p;
vis[p]=1;
p=pos[p];
while(p!=i){
q[++cnt]=p;
vis[p]=1;
p=pos[p];
}
for(int j=1;j<=cnt;j++) ans[q[j]]=a[q[(j+k-1)%cnt+1]];
}
for(int i=1;i<=n;i++){
ans[i]+=ans[i-1];
printf("%lld.0\n",ans[i]);
}
return 0;
} | #include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
using namespace std;
int main()
{
int n, q;
cin >> n >> q;
string s;
cin >> s;
int a[N];
a[0] = 1;
for (int i = 1; i < n; ++i)
{
if (s[i] == 'C' && s[i - 1] == 'A')
{
a[i] = a[i - 1] + 1;
}
else
{
a[i] = a[i - 1];
}
}
int l, r;
rep(i, q)
{
cin >> l >> r;
cout << a[r - 1] - a[l - 1] << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main () {
int N;
cin >> N;
if (N == 1){
cout << 1 << endl;
return 0;
}
vector<int>A(N);
vector<vector<vector<int>>> data(N, vector<vector<int>>(N, vector<int>(2)));
for (int i = 0; i < N; i++) {
cin >> A.at(i);
for (int j = 0; j < A.at(i); j++) {
for (int k = 0; k < 2; k++) {
cin >> data.at(i).at(j).at(k);
}
}
}
int Max = 0;
// すべての選び方を試して、総和がKになるものがあるかを調べる
for (int tmp = 0; tmp < (1 << 15); tmp++) {
bitset<15> s(tmp); // 最大20個なので20ビットのビット列として扱う
if (N < 15 && s.test(N)) {
break;
}
// ビット列の1のビットに対応する整数を選んだとみなして総和を求める
int count = 0;
int honest = 0;
for (int i = 0; i < N; i++) {
if (s.test(i)) {
honest++;
for (int j = 0; j < A.at(i); j++) {
int B = data.at(i).at(j).at(0) - 1;
if (s.test(B)){
if (data.at(i).at(j).at(1) == 0){
count++;
}
}
else {
if (data.at(i).at(j).at(1) == 1){
count++;
}
}
}
}
}
if (count == 0){
if (honest > Max){
Max = honest;
}
}
}
cout << Max << 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, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
void solve() {
int n, ans = 0;
cin >> n;
vector<pii> A[n];
rep(i, n) {
int a;
cin >> a;
rep(j, a) {
int x, y;
cin >> x >> y;
x--;
A[i].push_back({x, y});
}
}
rep(bit, 1 << n) {
rep(i, n) {
if ((bit >> i & 1) == 0) continue;
rep(j, A[i].size()) {
int x, y;
tie(x, y) = A[i][j];
if ((bit >> x & 1) != y) {
goto end;
}
}
}
chmax(ans, __builtin_popcount(bit));
end:;
}
cout << ans << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a,b;
cin>>a>>b;
if(n%2==0)cout<<a+b<<endl;
else cout<<"Hello"<<" "<<"World"<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int ans=0,N,X,T;
cin >> N >> X >> T;
if(N%X){
ans = (N/X+1)*T;
}else{
ans = (N/X)*T;
}
cout << ans << endl;
return 0;
} | 0 |
#include <iostream>
using namespace std;
int main() {
int x,y;
cin >> x >> y;
if (x == 1 && y == 1) {
cout << 1000000 << endl;
} else {
cout << (max(0,4-x)+max(0,4-y))*100000 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int A, B;
cin >> A >> B;
if (B == 1) {
cout << 0 << endl;
return 0;
}
int output = 1;
int socket = A;
while (1) {
if (socket >= B) break;
socket--;
socket += A;
output++;
}
cout << output << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
int K,T;
cin >> K >> T;
int a[T];
for (int i = 0; i < T; i++) {
cin >> a[i];
}
sort(a,a+T);
reverse(a,a+T);
int ma = max(0,a[0] - (K - a[0]));
int ans = max(0,ma-1);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
int main() {
int K, T;
cin >> K >>T;
vector<int> A(T);
rep(i, T)
cin >> A[i];
if(T==1) {
cout << K-1 << endl;
return 0;
}
sort(A.rbegin(), A.rend());
int64_t ret = A[0];
int64_t sum = 0;
rep(i, A.size()-1) {
sum += A[i+1];
}
if(ret-sum-1 <= 0) {
ret = 0;
} else {
ret = ret-sum-1;
}
cout << ret << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 211;
const ll INF = 5e16;
const ll P = 1e9 + 7;
namespace IO {
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 dd ch = getchar()
inline ll read() {
R ll x = 0; R int f = 0; R char dd;
for (; !isdigit(ch); dd) f ^= (ch == '-');
for (; isdigit(ch); dd) x = x * 10 + (ch ^ 48);
return f? -x: x;
}
#undef dd
inline void write ( ll x ) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10); putchar(x % 10 | 48);
}
inline void wrn ( ll x ) { write(x), putchar(' '); }
inline void wln ( ll x ) { write(x), putchar('\n'); }
inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }
}
using IO::wln;
using IO::read;
namespace Cesare {
/*
最小的用掉后答案就不会变了。
设 f[i][0/1] 表示做了 i 次,
最小的被用掉/没被用掉的答案。
枚举 s[n] 在什么时候被用掉。
对于每个 pos, 其他有 (n - 1)! 种排列
方式。
但只有前 pos - 1 个会对答案造成贡献,
所以考虑怎么选择这前 pos - 1 个。
每次操作就是把 X % s[i]
前面的思路都是对的!就是不会设计状态了。
设 f[i][j] 表示做了 i 次,当前数为 j 。
f[i][j % a[i]] = f[i - 1][j] * (n - i + 1)
*/
const ll M = 100011;
ll n, X, Ans, s[N], f[N][M];
inline void Add ( ll &a, ll b ) { (a += b) >= P && (a -= P); }
int main() {
n = read(), X = read();
For ( i, 1, n ) s[i] = read();
sort(s + 1, s + n + 1, greater <ll> ());
f[0][X] = 1;
For ( i, 1, n ) For ( j, 0, X )
(f[i][j % s[i]] += f[i - 1][j]) %= P,
(f[i][j] += f[i - 1][j] * (n - i)) %= P;
For ( i, 1, X ) Add(Ans, f[n][i] * i % P);
return wln(Ans), 0;
}
}
int main()
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
return Cesare :: main();
}
/*
*/
| #include <bits/stdc++.h>
using namespace std;
const int MAX = 3000005;
const int MOD = 998244353;
long long fac[MAX]; //i!%MOD=fac[i]
long long finv[MAX]; //pow(i!,-1)%MOD=finv[i]
long long inv[MAX]; //pow(i,-1)%MOD=inv[i]
// テーブルを作る前処理
void COMinit() {
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;
}
}
// 二項係数計算
long long COM(int n, int 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(int argc, char const *argv[])
{
COMinit();
int n,m;
cin>>n>>m;
long long ans=COM(3*m+n-1,n-1);
for (int i = 2*m+1; i <= 3*m; ++i)
{
ans-=(long long)n*COM(3*m+n-2-i,n-2)%MOD;
ans%=MOD;
}
for (int i = 0; i < m; ++i)
{
ans-=COM(n-1+i,n-1)*COM(n,3*m-2*i)%MOD;
ans%=MOD;
}
ans+=MOD;
ans%=MOD;
cout<<ans<<endl;
return 0;
}
| 0 |
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"
#define ll long long
#define int ll
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define node(a,b,c) mp(mp(a,b),c)
#define clr(x) memset(x,0,sizeof(x));
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
map<int,pi>yo;
main()
{
fast
int n;
cin>>n;
f(i,1,n)
{
int x,y;
cin>>x>>y;
yo[x]=(mp(y,0));
}
f(i,1,n)
{
int x,y;
cin>>x>>y;
yo[x]=(mp(y,1));
}
int ses=0;
set<int>s;
set<int>::iterator it;
for(auto z:yo)
{
int x=z.fi;
int typ=z.si.si;
int y=z.si.fi;
if(typ==0)
{
s.insert(y);
}
else
{
if(s.empty())continue;
it=s.upper_bound(y);
if(it==s.begin())continue;
it--;
s.erase(it);
ses++;
}
}
cout<<ses<<"\n";
return 0;
}
| #include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct edge{
int to;
int cap;
int rev;
};
struct Dinic{
int V;
vector<int> level, used;
vector<vector<edge>> G;
Dinic(int N){
V = N;
used.resize(V, 0);
level.resize(V, -1);
G.resize(V);
}
void add(int u, int v, int c){
edge e1 = {v, c, (int)G[v].size()};
G[u].push_back(e1);
edge e2 = {u, 0, (int)G[u].size() - 1};
G[v].push_back(e2);
}
void bfs(int s){
level.assign(V, -1);
queue<int> q;
q.push(s);
level[s] = 0;
while(!q.empty()){
int v = q.front();
q.pop();
for(edge e: G[v]){
if(e.cap > 0 && level[e.to] < 0){
level[e.to] = level[v] + 1;
q.push(e.to);
}
}
}
}
int dfs(int s, int t, int f){
if(s == t) return f;
for(int &i = used[s]; i < (int)G[s].size(); i++){
edge &e = G[s][i];
if(e.cap > 0 && level[e.to] > level[s]){
int d = dfs(e.to, t, min(f, e.cap));
if(d > 0){
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int solve(int s, int t){
int flow = 0;
int INF = 1e9;
while(1){
bfs(s);
if(level[t] < 0) return flow;
used.assign(V, 0);
int f;
while((f = dfs(s, t, INF)) > 0) flow += f;
}
}
};
int main(){
int N;
cin >> N;
Dinic Ford(2 * N + 2);
int can[N][N];//can[i][j] = 1でペアが作れる
vector<int> a(N), b(N), c(N), d(N);
for(int i = 0; i < N; i++) cin >> a[i] >> b[i];
for(int i = 0; i < N; i++) cin >> c[i] >> d[i];
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(a[i] < c[j] && b[i] < d[j]) can[i][j] = 1;
else can[i][j] = 0;
}
}
for(int i = 0; i < N; i++){
Ford.add(2 * N, i, 1);
Ford.add(N + i, 2 * N + 1, 1);
}
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(can[i][j]) Ford.add(i, N + j, 1);
}
}
int ans = Ford.solve(2 * N, 2 * N + 1);
cout << ans << endl;
} | 1 |
#include <bits/stdc++.h>
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
using namespace std;
const int MOD=1e9+7;
int D[1<<20], Dsum[1<<20], Dminus[1<<20], PS[500001];
long long mod(long long a)
{
if(a>=0) return a%MOD;
return ((-a/MOD+1)*MOD+a)%MOD;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
TEST(freopen("input.txt","r",stdin));
TEST(freopen("output.txt","w",stdout));
TEST(freopen("debug.txt","w",stderr));
int N, PX=0, A;
cin>>N; PS[0]=1;
for(int i=1;i<=N;i++) {
cin>>A;
if(PX^=A) {
D[PX]=mod(1+1LL*Dsum[PX]*PS[i-1]-1LL*Dminus[PX]);
Dsum[PX]=(Dsum[PX]+D[PX])%MOD;
Dminus[PX]=(Dminus[PX]+1LL*D[PX]*PS[i-1])%MOD;
}
else PS[i]=1;
PS[i]+=PS[i-1];
}
if(PX) cout<<D[PX]<<'\n';
else {
int ans=1;
for(int i=2;i<PS[N];i++) ans=(2*ans)%MOD;
for(int i=(1<<20)-1;i;i--) ans=(ans+Dsum[i])%MOD;
cout<<ans<<'\n';
}
return 0;
} | /** Created by: Marcos Portales
Codeforces User: marcosportales
Country: Cuba
Copyright */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long , null_type , less<long long> , rb_tree_tag , tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
if( !e ) return 1;
if( e & 1 ) return qpow(b,e-1) * b % mod;
int pwur = qpow(b,e>>1);
return (pwur * pwur) % mod;
}
int modinv(int x){
return qpow(x,mod-2);
}
/// My Code -------------------------------------------------
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(0);
srand(time(NULL));
//freopen("a.in","r",stdin);
//freopen("a.in","w",stdout);
int n;
cin>>n;
vi v(n);
int ans=0;
rep(i,n){
cin>>v[i];
}
bool fl=1;
while(1){
rep(i,n){
if(v[i]%2)fl=0;
}
if(!fl)break;
rep(i,n)v[i]/=2;
ans++;
}
cout<<ans<<enl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()
long double dp[301][301][301];
long double N;
long double solve(int ones, int twos, int threes){
if(dp[ones][twos][threes] >= 0) return dp[ones][twos][threes];
long double cur = 1;
if(threes > 0) cur += (threes/N) * (solve(ones,twos+1,threes-1));
if(twos > 0) cur += (twos/N) * (solve(ones+1,twos-1,threes));
if(ones > 0) cur += (ones/N) * (solve(ones-1,twos,threes));
cur *= N / (ones+twos+threes);
return dp[ones][twos][threes] = cur;
}
void solution(){
// expected value dp -- states are messed up, use top down to simplify implementation
int n; cin >> n;
N = (long double)n;
vector<int> a(n); for(auto& x : a) cin >> x;
int ones = 0, twos = 0, threes = 0;
for(int x : a){
if(x == 1) ones++;
else if(x == 2) twos++;
else threes++;
}
memset(dp,-1,sizeof(dp));
dp[0][0][0] = 0;
printf("%0.14Lf\n", solve(ones,twos,threes));
}
int main(){
fio; // fast input output
int t;
t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
// GOOGLE //
// cout << "Case #" << i << ": ";
solution();
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,id[maxn],omove,orev,emove,erev,bit[maxn],rnk[maxn];
bool rev[maxn],vis[maxn];
inline void wrong(){
puts("No");
exit(0);
}
inline void add(int x,int val){
while(x<maxn){
bit[x]+=val;
x+=x&-x;
}
}
inline int sum(int x){
int res=0;
while(x){
res+=bit[x];
x-=x&-x;
}
return res;
}
int main(){
cin>>n;
for(int i=1,a;i<=n;++i){
cin>>a;
id[i]=(a+2)/3;
rnk[id[i]]=i;
if(vis[id[i]]||a==3*id[i]-1)
wrong();
vis[id[i]]=true;
if(a==3*id[i])
rev[i]=true;
}
for(int i=1,a;i<=n;++i){
cin>>a;
if(a!=3*id[i]-1)
wrong();
}
for(int i=1,a;i<=n;++i){
cin>>a;
if(rev[i]&&a!=3*id[i]-2||!rev[i]&&a!=3*id[i])
wrong();
}
for(int i=1;i<=n;++i)
if((i&1)!=(id[i]&1))
wrong();
for(int i=1;i<=n;i+=2)
add(i,1);
for(int i=1;i<=n;i+=2){
add(rnk[i],-1);
omove+=sum(rnk[i]);
orev+=rev[i];
}
memset(bit,0,sizeof(bit));
for(int i=2;i<=n;i+=2)
add(i,1);
for(int i=2;i<=n;i+=2){
add(rnk[i],-1);
emove+=sum(rnk[i]);
erev+=rev[i];
}
if((omove&1)!=(erev&1)||(emove&1)!=(orev&1))
wrong();
puts("Yes");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
int n,h,v;
cin >> n >> h >> v;
cout << (n - h + 1) * (n - v + 1) ;
}
| #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() {
int x;
cin >> x;
int ans = 0;
ans += x / 500 * 1000;
x %= 500;
ans += x / 5 * 5;
cout << ans << endl;
return 0;
} | 0 |
//Author:xht37
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double
#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)
#define vi vector <int>
#define pb push_back
#define pq priority_queue
#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
inline void flush() {
fwrite(OB, 1, OS - OB, stdout), OS = OB;
}
inline void pc(char x) {
*OS++ = x;
if (OS == OT) flush();
}
template <class I>
inline void rd(I &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
x *= f;
}
template <class I>
inline void rd(I &x, I &y) {
rd(x), rd(y);
}
template <class I>
inline void rd(I &x, I &y, I &z) {
rd(x), rd(y), rd(z);
}
template <class I>
inline void rda(I *a, int n) {
for (int i = 1; i <= n; i++) rd(a[i]);
}
inline void rdc(char &c) {
for (c = gc(); c < 33 || c > 126; c = gc());
}
inline void rds(char *s, int &n) {
for (c = gc(); c < 33 || c > 126; c = gc());
for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
s[n+1] = '\0';
}
inline void rds(string &s) {
for (c = gc(); c < 33 || c > 126; c = gc());
for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
}
template <class I>
inline void print(I x, char k = '\n') {
if (!x) pc('0');
if (x < 0) pc('-'), x = -x;
while (x) ch[++t] = x % 10 + '0', x /= 10;
while (t) pc(ch[t--]);
pc(k);
}
template <class I>
inline void print(I x, I y) {
print(x, ' '), print(y);
}
template <class I>
inline void print(I x, I y, I z) {
print(x, ' '), print(y, ' '), print(z);
}
template <class I>
inline void printa(I *a, int n) {
for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
}
inline void printc(char c) {
pc(c);
}
inline void prints(char *s, int n) {
for (int i = 1; i <= n; i++) pc(s[i]);
pc('\n');
}
inline void prints(string s) {
int n = s.length();
while (t < n) pc(s[t++]);
pc('\n'), t = 0;
}
struct Flush {
~Flush() {
flush();
}
} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;
const int N = 1e5 + 7;
int n;
ll s, x[N], p[N];
ll f(int l, int r, int o) {
if (s < x[l] || x[r] < s) return abs(s - x[o]);
if (p[l] >= p[r]) return p[l] += p[r], f(l, r - 1, l) + abs(x[l] - x[o]);
return p[r] += p[l], f(l + 1, r, r) + abs(x[r] - x[o]);
}
int main() {
rd(n), rd(s);
for (int i = 1; i <= n; i++) rd(x[i], p[i]);
print(f(1, n, s < x[1] ? n : x[n] < s ? 1 : p[1] >= p[n] ? n : 1));
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
if (!b) return 1;
ll ns = ksm(a, b >> 1);
ns = ns * ns % mod;
if (b & 1) ns = ns * a % mod;
return ns;
}
int n, s;
ll ans;
int x[maxn];
ll p[maxn];
ll ttm[maxn];
int ls[maxn], pp[maxn];
void caltm(int a) {
if (!ls[a]) return ;
else if (ttm[a]) return ;
else caltm(ls[a]), ttm[a] = ttm[ls[a]] + pp[a];
}
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++)
scanf("%d%d", &x[i], &p[i]);
int l = 1, r = n;
while (1) {
if (s <= x[l] || s >= x[r]) {
for (int i = l; i <= r; i++)
ttm[i] = abs(s - x[i]);
break;
}
if (p[l] >= p[r]) {
ls[r] = l, pp[r] = x[r] - x[l];
p[l] += p[r], r--;
}
else {
ls[l] = r, pp[l] = x[r] - x[l];
p[r] += p[l], l++;
}
}
for (int i = 1; i <= n; i++)
caltm(i), ans = max(ans, ttm[i]);//, cout << ttm[i] << ' ' << ls[i] << ' ' << pp[i] << endl;
cout << ans << endl;
return 0;
}
| 1 |
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a<=8&&b<=8)
cout<<"Yay!\n";
else
cout<<":(\n";
} | #include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define endl "\n"
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define ROF(i, a, n) for (ll i = a; i >= n; i--)
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x,val,sizeof(x))
#define dline cout<<"///REACHED///\n";
typedef long long ll;
const ll MOD = 1e+9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MAXN = 4e+5+7;
// 6
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a,b;
cin>>a>>b;
if(((16-(2*min(a,b))+1)/2+min(a,b))>= max(a,b)){
cout<<"Yay!";
}
else{
cout<<":(";
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define lop(i, n) for (int i = 0; i < (n); ++i)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a,b,c;
cin>>a>>b>>c;
int a1 = a + b;
int a2 = a + c;
int a3 = b + c;
if (a1 <= a2 && a1 <= a3) {
cout<<(a1);
} else if (a2 <= a1 && a2 <= a3) {
cout<<(a2);
} else if (a3 <= a1 && a3 <= a2) {
cout<<(a3);
}
} | #include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define mk(arr,n,type) type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "Yes"<<endl
#define no cout<< "No"<<endl
#define all(v) (v).begin(),(v).end()
#define mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
void fastio()
{
#ifndef ONLINE_JUDGE
freopen("INPUT.txt","r",stdin);
freopen("OUTPUT.txt","w",stdout);
#endif
ios_base :: sync_with_stdio(false);
cin.tie(NULL) ;
cout.tie(NULL);
}
signed main()
{
fastio();
int t=1;
// cin>>t;
while(t--)
{
int a[3];
for(int i=0;i<3;i++)
cin>>a[i];
sort(a,a+3);
cout<<a[0]+a[1];
}
}
// 🍪 🍪 🍪 | 1 |
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int n;
while(cin>>n,n){
long long int syain,kakaku,kosuu,syains[5000]={0};
long long int bango[5000]={0},flag[5000]={0};
bool flag2=0;
for(int i=0;i<n;i++){
cin>>syain>>kakaku>>kosuu;
bango[i]=syain;
syains[syain]+=kakaku*kosuu;
}
for(int i=0;i<5000;i++){
if(syains[bango[i]]>=1000000){
if(flag[bango[i]]==0){
cout<<bango[i]<<endl;
flag[bango[i]]=1;
}
}
}
for(int i=0;i<5000;i++){
if(flag[i]==1)flag2=1;
}
if(flag2==0)cout<<"NA"<<endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
struct EmployeeSale {
long employee_number;
long long sales;
};
int main()
{
int data_count = 0;
while (std::cin >> data_count) {
if (data_count == 0) {
break;
}
std::vector<EmployeeSale> sales_per_employee;
for (int i = 0; i < data_count; ++i) {
long employee_number = 0;
long unit_price = 0;
long quantity = 0;
if (std::cin >> employee_number >> unit_price >> quantity) {
long long each_sales = static_cast<long long>(unit_price) * quantity;
auto it = std::find_if(
sales_per_employee.begin(),
sales_per_employee.end(),
[=](EmployeeSale const& sale){ return sale.employee_number == employee_number; });
if (it != sales_per_employee.end()) {
it->sales += each_sales;
} else {
EmployeeSale sales = { employee_number, each_sales };
sales_per_employee.push_back(sales);
}
}
}
std::vector<EmployeeSale> sales_achieved;
std::copy_if(
sales_per_employee.begin(),
sales_per_employee.end(),
std::back_inserter(sales_achieved),
[](EmployeeSale const& sale){ return sale.sales >= 1000000; });
if (!sales_achieved.empty()) {
std::for_each(
sales_achieved.begin(),
sales_achieved.end(),
[](EmployeeSale const& sale){ std::cout << sale.employee_number << std::endl; });
} else {
std::cout << "NA\n";
}
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
int n;
string ans, newans;
int main() {
cin.tie(0), ios::sync_with_stdio(0);
cin >> n;
cout << "0\n";
cout.flush();
cin >> ans;
if(ans == "Vacant"){
cout << "0\n";
cout.flush();
cin >> ans;
exit(0);
}
int pos = 0;
for(int i = 17; i >= 0; i--){
if(pos + (1 << i) < n){
cout << pos + (1 << i) << "\n";
cout.flush();
cin >> newans;
if(newans == "Vacant"){
cout << pos + (1 << i) << "\n";
cout.flush();
cin >> newans;
exit(0);
}
if(ans == newans)
pos += (1 << i);
}
}
cout << pos + 1 << "\n";
cout.flush();
cin >> newans;
exit(0);
}
|
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;
template<class _T> static void get(_T& a) {
std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
if (sizeof(_T) > sizeof(int)) {
scanf("%lld", &a);
}
else {
scanf("%d", &a);
}
}
static void exec();
int main()
{
exec();
fflush(stdout);
return 0;
}
static void exec()
{
int N;
get(N);
int now = 0, start = 0;
int end = N;
std::string ans;
printf("%d\n", now);
fflush(stdout);
get(ans);
std::string even = ans;
std::string odd = "Female";
if (even == odd) odd = "Male";
while (ans != "Vacant") {
now = (start + end) / 2;
printf("%d\n", now);
fflush(stdout);
get(ans);
if (((now % 2) && (ans == odd)) || ((now % 2 == 0) && (ans == even))) {
start = now;
}
else {
end = now;
}
}
}
| 1 |
#include <iostream>
using namespace std;
int main() {
int N, K; cin >> N >> K;
int ans = 0;
for (int i = 1; i <= N; i++) if (i + (K - 1) <= N) ans++;
printf("%d\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
int main() {
int N, K;
cin >> N >> K;
cout << N - K + 1 << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string A,B,C;
cin >> A >> B >> C;
int D = A.size() - 1;
int E = B.size() - 1;
int F = C.size() - 1;
if(A[D] == B[0] && B[E] == C[0]){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
| #include <bits/stdc++.h>
#define TOP 0
#define FRONT 1
#define LEFT 2
#define RIGHT 3
#define BACK 4
#define BOTTOM 5
using namespace std;
//TOP,FRONT,LEFT,RIGHT,BACK,BOTTOM
int dice[6]={1,2,4,3,5,6};
//?\\?????¢??????
void rotN(){
swap(dice[TOP],dice[FRONT]);
swap(dice[FRONT],dice[BOTTOM]);
swap(dice[BOTTOM],dice[BACK]);
}
//???????????¢??????
void rotS(){
//rotN(),rotN(),rotN();
swap(dice[TOP],dice[BACK]);
swap(dice[BACK],dice[BOTTOM]);
swap(dice[BOTTOM],dice[FRONT]);
}
//????????¢??????
void rotE(){
swap(dice[TOP],dice[LEFT]);
swap(dice[LEFT],dice[BOTTOM]);
swap(dice[BOTTOM],dice[RIGHT]);
}
//????????¢??????
void rotW(){
//rotE(),rotE(),rotE();
swap(dice[TOP],dice[RIGHT]);
swap(dice[RIGHT],dice[BOTTOM]);
swap(dice[BOTTOM],dice[LEFT]);
}
//???????????????????¨????????????????
void rotCW(){
swap(dice[FRONT],dice[RIGHT]);
swap(dice[RIGHT],dice[BACK]);
swap(dice[BACK],dice[LEFT]);
}
//??????????????????????¨???????????????????
void rotCCW(){rotCW(),rotCW(),rotCW();}
int main(){
cin>>dice[TOP]>>dice[FRONT]>>dice[RIGHT];
cin>>dice[LEFT]>>dice[BACK]>>dice[BOTTOM];
string str;
cin>>str;
for(int i=0;i<str.size();i++){
if(str[i]=='N') rotN();
if(str[i]=='S') rotS();
if(str[i]=='E') rotE();
if(str[i]=='W') rotW();
}
cout << dice[TOP]<<endl;
} | 0 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)
//-------------------------------------------------------//
int main() {
string s;
int k;
cin >> k >> s;
if((int)s.size() > k) {
s = s.substr(0,k);
s += "...";
}
cout << s << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
long long k, n;
string s;
cin >> k >> s;
n = (long long)(s.length());
if (k >= n){
cout << s << endl;
}
else{
cout << s.erase(k) << "..." << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll x,y;
cin >> x >> y;
ll ans = 0;
if (x * y > 0){
if (x <= y){
ans = y-x;
}
else{
ans = x-y+2;
}
}
else if (x * y == 0){
if (x == 0){
if (y >= 0){
ans = y;
}
else{
ans = abs(y)+1;
}
}
else{
if (x < 0){
ans = abs(x);
}
else{
ans = x+1;
}
}
}
else{
if (abs(x) >= abs(y)){
ans = abs(x)-abs(y)+1;
}
else{
ans = abs(y)-abs(x)+1;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=2e6+10;
const ll mod=998244353;
ll inv(ll x){
ll ans=1;
for(ll i=mod-2;i;i>>=1,x=x*x%mod)if(i&1)ans=ans*x%mod;
return ans;
}
ll fact[mn];
ll ch(ll n,ll k){
if(k<0||k>n)return 0;
return fact[n]*inv(fact[k])%mod*inv(fact[n-k])%mod;
}
ll hail(ll k,ll n,ll m){
m++;
return ch(k+n-1,n-1)-n*ch(k+n-1-m,n-1)%mod;
}
int main()
{
ll n,m,i;
fact[0]=1;
for(i=1;i<mn;i++)fact[i]=fact[i-1]*i%mod;
scanf("%lld%lld",&n,&m);
ll ans=0;
for(i=m%2;i<=min(n,m);i+=2){
ans+=ch(n,i)*hail((3*m-i)/2,n,m-1)+(hail((3*m-i)/2,n,m)-hail((3*m-i)/2,n,m-1))*ch(n-1,i);
ans%=mod;
}
if(ans<0)ans+=mod;
printf("%lld",ans);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxN = 2000 + 5;
int n;
LL P;
LL f[maxN * 3][maxN];
int main() {
cin >> n >> P;
f[0][0] = 1;
for(int i = 0; i <= n * 3; ++i) {
for(int j = 0; j <= i / 2 && j <= n; ++j) {
(f[i + 1][j] += f[i][j]) %= P;
(f[i + 2][j + 1] += f[i][j] * (i + 1)) %= P;
(f[i + 3][j + 1] += f[i][j] * (i + 2) % P * (i + 1)) %= P;
}
}
LL ans = 0;
for(int j = 0; j <= n; ++j) (ans += f[3 * n][j]) %= P;
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2000+5,base=2001*3;
int f[N*3][N*6],mod;
void add(int &x,int y){
x=(x+y)%mod;
}
signed main(){
int n;
cin>>n>>mod;
n*=3;
f[0][base]=1;
for(int i=0;i<n;++i)
for(int j=-i;j<=i;++j)
if(f[i][j+base]){
add(f[i+1][j+1+base],f[i][j+base]);
add(f[i+2][j-1+base],1ll*f[i][j+base]*(i+1)%mod);
add(f[i+3][j+base],1ll*f[i][j+base]*(i+1)%mod*(i+2)%mod);
}
int ans=0;
for(int j=0;j<=n;++j)
add(ans,f[n][j+base]);
cout<<ans;
return 0;
} | 1 |
#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 whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
// Morris-Pratt
// https://youtu.be/9MphwmIsO7Q?t=7283
template<typename T>
struct MP {
int n;
T t;
vector<int> a;
MP() {}
MP(const T& t): t(t) {
n = t.size();
a = vector<int>(n+1);
a[0] = -1;
int j = -1;
for (int i = 0; i < n; ++i) {
while (j != -1 && t[j] != t[i]) j = a[j];
j++;
a[i+1] = j;
}
}
int operator[](int i) { return a[i];}
vector<int> findAll(const T& s) {
vector<int> res;
int j = 0;
for (int i = 0; i < s.size(); ++i) {
while (j != -1 && t[j] != s[i]) j = a[j];
j++;
if (j == n) {
res.push_back(i-j+1);
j = a[j];
}
}
return res;
}
};
int main(){
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vector<ll> ax(n);
vector<ll> bx(n);
rep(i, n) {
ax[i] = a[i]^a[(i+1)%n];
bx[i] = b[i]^b[(i+1)%n];
}
ax.insert(ax.end(), ax.begin(), ax.end());
MP<vector<ll>> mp(bx);
vector<int> match = mp.findAll(ax);
for (int e:match) {
if (e>=n) continue;
ll x = a[e] ^ b[0];
cout << e << " " << x << endl;
}
//cout << ans << endl;
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> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
bool f(P l,P r){
int a = l.second - l.first;
int b = r.second - r.first;
if(a > 0 && b <= 0){
return true;
}
if(a <= 0 && b > 0){
return false;
}
if(a > 0 && b > 0){
return l.first < r.first;
}if(a < 0 && b < 0){
return l.second > r.second;
}
}
int main(){
int n;
cin >> n;
vector<string> s(n);
rep(i,n) cin >> s[i];
vector<P> lr(n);
rep(i,n){
int l = 0;
int r = 0;
rep(j,s[i].size()){
if(s[i][j] == '('){
++r;
}else{
if(r > 0) --r;
else ++l;
}
}
lr[i].first = l;
lr[i].second = r;
}
sort(lr.begin(),lr.end(),f);
if(lr[0].first!=0){
cout << "No" << endl;
return 0;
}
int l = 0;
int r = 0;
rep(i,n){
if(r < lr[i].first){
cout << "No" << endl;
return 0;
}
r -= lr[i].first;
r += lr[i].second;
}
cout << (r==0?"Yes":"No") << endl;
return 0;
}
| 0 |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#define ll long long
using namespace std;
ll _11[18];
int main()
{
ll d;
scanf("%lld",&d);
if(d%9){puts("0");return 0;}
d/=9;
ll ans=0;
for(int i=1;i<=17;i++) _11[i]=_11[i-1]*10+1;
ll len=1;
for(int i=1;i<=17;i++)
{
ll res=1,del=d,L=len,R=1,b=_11[i];
for(int j=0;j<=(i>>1);j++)
{
res*=10-abs(del%(R*10)/R)-(!j);
del-=b*(del%(R*10)/R);
b-=L+R;
L/=10;
R*=10;
}
if(!del) ans+=res;
len*=10;
}
printf("%lld",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
int e;
cin >>e;
while(e)
{
int x=0;
int y=0;
int z=0;
int m=0;
for(z=0;z*z*z<=e;z++)
for(y=0;z*z*z+y*y<=e;y++)
{
x = e-z*z*z-y*y;
if(x<0)
continue;
int t = x+y+z;
if(m ==0||m>t)
m=t;
}
cout <<m<<endl;
cin >>e;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int k;
int numShow = 1;
int minNumber = 9999999;
cin >> n >> k;
for (int i = 0; i < n; i++) {
// 操作Aの処理
for (int a = i; a < n; a++) {
numShow *= 2;
if (numShow > minNumber) {
break;
}
}
// 操作Bの処理
for (int b = n - i; b < n; b++) {
numShow += k;
if (numShow > minNumber) {
break;
}
}
if (numShow < minNumber) {
minNumber = numShow;
}
numShow = 1;
}
cout << minNumber << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 * 2;
int main() {
int n, k;
cin >> n >> k;
int num = 1;
rep(i, n){
num += min(num, k);
}
cout << num << endl;
}
| 1 |
#include <array>
#include <cstdlib>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
class SSF {
private:
void ScanLine(std::vector<std::string> *map, const char lx, const char rx, const char y, const char oy, std::array<std::queue<char>, 4> *buffer) {
unsigned char i = lx;
while (i <= rx) {
while (i < rx) {
if (map->at(y).at(i) != '0') {
break;
}
++i;
}
if (map->at(y).at(i) == '0') {
break;
}
buffer->at(0).push(i);
while (i <= rx) {
if (map->at(y).at(i) == '0') {
break;
}
++i;
}
buffer->at(1).push(i - 1);
buffer->at(2).push(y);
buffer->at(3).push(oy);
}
return;
}
public:
unsigned char SeedFill(std::vector<std::string> *map, const unsigned char x, const unsigned char y) {
std::array<std::queue<char>, 4> buffer;
unsigned char lx, rx, ly, oy;
if (map->at(y).at(x) == '0' || map->empty() == true) {
return 0;
}
buffer.at(0).push(x);
buffer.at(1).push(x);
buffer.at(2).push(y);
buffer.at(3).push(y);
while (buffer.front().empty() == false) {
char lxsav = buffer.at(0).front() - 1, rxsav = buffer.at(1).front() + 1;
lx = buffer.at(0).front();
buffer.at(0).pop();
rx = buffer.at(1).front();
buffer.at(1).pop();
ly = buffer.at(2).front();
buffer.at(2).pop();
oy = buffer.at(3).front();
buffer.at(3).pop();
if (map->at(ly).at(lx) == '0') {
continue;
}
while (rx < map->at(ly).size() - 1) {
if (map->at(ly).at(rx + 1) == '0') {
break;
}
++rx;
}
while (lx > 0) {
if (map->at(ly).at(lx - 1) == '0') {
break;
}
--lx;
}
for (unsigned char i = lx; i <= rx; ++i) {
map->at(ly).at(i) = '0';
}
if (ly - 1 >= 0) {
if (ly - 1 == oy) {
ScanLine(map, lx, lxsav, ly - 1, ly, &buffer);
ScanLine(map, rxsav, rx, ly - 1, ly, &buffer);
}
else {
ScanLine(map, lx, rx, ly - 1, ly, &buffer);
}
}
if (ly + 1 <= map->size() - 1) {
if (ly + 1 == oy) {
ScanLine(map, lx, lxsav, ly + 1, ly, &buffer);
ScanLine(map, rxsav, rx, ly + 1, ly, &buffer);
}
else {
ScanLine(map, lx, rx, ly + 1, ly, &buffer);
}
}
}
return 1;
}
};
int main() {
while (1) {
SSF ssf;
std::vector<std::string> map;
unsigned short count = 0;
do {
map.resize(count + 1);
std::getline(std::cin, map.at(count));
if (map.at(count).empty() == true) {
std::getline(std::cin, map.at(count));
if (map.at(count).empty() == true) {
return EXIT_SUCCESS;
}
}
map.at(count).resize(map.front().size(), '0');
map.at(count).shrink_to_fit();
} while (++count < map.front().size());
map.shrink_to_fit();
count = 0;
for (unsigned char j = 0; j < map.size(); ++j) {
for (unsigned char i = 0; i < map.at(j).size(); ++i) {
count += ssf.SeedFill(&map, i, j);
}
}
std::cout << count << std::endl;
}
return EXIT_SUCCESS;
} | #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
queue<PA> que;
int main(){
int n,ans;
char m[13][13];
while(cin >> m[0]){
for(int j = 0;j < 12;j++){
if(j==0) continue;
cin >> m[j];
}
ans = 0;
for(int j = 0;j < 12;j++){
for(int k = 0;k < 12;k++){
if(m[j][k] == '1'){
que.push(PA(j,k));
while(!que.empty()){
PA p=que.front();que.pop();
m[p.first][p.second] = '0';
for(int l = 0;l < 4;l++){
int y = p.first+dy[l];
int x = p.second+dx[l];
if(x<0||y<0||x>=12||y>=12||m[y][x]=='0') continue;
que.push( PA(y,x) );
}
}
ans++;
}
}
}
cout << ans << endl;
}
return (0);
} | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main() {
int n; cin >> n;
string s;
getline(cin, s);
while(n--) {
getline(cin, s);
rep(i, s.size()) {
if(s.substr(i, 7) == "Hoshino") s[i+6] = 'a';
}
cout << s << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string az="abcdefghijklmnopqrstuvwxyz";
string s;
cin >> s;
sort(s.begin(),s.end());
int i=0,j=0;
for(int j=0;j<s.length();j++) {
if(az[i]==s[j]) {
i++;
}
if(i==26) {
cout << "None" << endl;
return 0;
}
}
cout << az[i];
}
| 0 |
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
int main() {
int n;
cin >> n;
int k = 0, l = 0, m = 0;
ll ret = 1;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (k == a) {
int count = 1;
k++;
if (l == a) count++;
if (m == a) count++;
ret = ret * count % mod;
}
else if (l == a) {
int count = 1;
l++;
if (m == a) count++;
ret = ret * count % mod;
}
else if (m == a) {
m++;
}
else {
ret = 0;
break;
}
}
cout << ret << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long n, long long p){
long long res = 1;
while(n > 0){
if(n & 1){
res = res*a%p;
}
a = a*a%p;
n >>=1;
}
return res;
}
int main()
{
int n;
long long ans = 0;
cin>> n;
vector<int> a(n);
vector<int> cnt(n);
for(int i=0;i<n;i++){
cin>> a[i];
}
int cnt0 = 3;
if(a[0] == 0){
ans = 3;
cnt[0]++;
cnt0--;
}
for(int i=1;i<n;i++){
if(a[i] == 0){
ans *= cnt0;
cnt0--;
cnt[0]++;
if(cnt0<0) ans = 0;
}else{
ans *= (cnt[a[i]-1] - cnt[a[i]]);
cnt[a[i]]++;
if(3<cnt[a[i]]) ans = 0;
}
if(1E9+7<=ans) ans %= (long long)(1E9+7);
}
cout<<ans<<endl;
}
| 1 |
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
while(1){
int N;
cin>>N;
if(!N)break;
int rui[10000]={0};
for(int i=1;i<=N;i++){
int a;
cin>>a;
rui[i]=rui[i-1]+a;
}
int ans=-2000000000;
//for(int i=0;i<=N;i++)printf("[%d]",rui[i]);
for(int i=0;i<=N;i++){
for(int j=i+1;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
}
cout<<ans<<endl;
}
return 0;
} | #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
signed main() {
for (int n; cin >> n&&n;) {
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> M(n);
for (int i = 0; i < n; i++) {
M[i] = a[i];
int temp = a[i];
for (int j = i + 1; j < n; j++) {
temp += a[j];
M[i] = max(M[i], temp);
}
}
cout << *max_element(ALL(M)) << endl;
}
return 0;
} | 1 |
#include <iostream>
using namespace std;
int main(){
int a,s;
while(cin>>a){//EOF?????§
s=0;
for(int i=a;i<600;i+=a){
s+=i*i*a;
}
cout<<s<<endl;
}
return 0;
}
| #include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif
#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/
int main() {
std::string s;
std::cin >> s;
std::map<char, lnt> map;
lnt n=s.size();
lnt ans=n*n;
for(auto c:s) map[c]++;
for(auto e:map) {
ans-=e.second*e.second;
}
print(ans/2+1);
}
| 0 |
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;
const int INF = 1 << 30;
const int V = 100000;
const int E = 500000;
struct Edge{ int to, cost; };
vector<Edge> list[E];
typedef pair<int, int> P;
int d[V];
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int v, e, r;
cin >> v >> e >> r;
int a, b, c;
for(int i = 0; i < e; ++i){
cin >> a >> b >> c;
list[a].push_back(Edge{b, c});
}
priority_queue<P, vector<P>, greater<P>> pque;
pque.push(P(0, r));
fill(d, d + v, INF);
d[r] = 0;
while(!pque.empty()){
P p = pque.top();
pque.pop();
int v1 = p.second;
if(d[v1] < p.first) continue;
for(int i = 0; i < list[v1].size(); ++i){
Edge e1 = list[v1][i];
if(d[e1.to] > d[v1] + e1.cost){
d[e1.to] = d[v1] + e1.cost;
pque.push(P(d[e1.to], e1.to));
}
}
}
for(int i = 0; i < v; ++i){
if(d[i] != INF)
cout << d[i] << endl;
else
cout << "INF" << endl;
}
return 0;
} | #include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int N=101;
int cost[N][N];
int tim[N][N];
int bfs(int n,int p,int q,int graph[N][N]){
vector<int> v(n);
queue<int> que;
rep(i,n)v[i]=INF;
v[p]=0;
que.push(p);
int u;
while(!que.empty()){
u=que.front(),que.pop();
rep(i,n){
if(v[i]>v[u]+graph[u][i]){
v[i]=v[u]+graph[u][i];
que.push(i);
}
}
}
return v[q];
}
signed main(){
int n,m;
while(cin>>n>>m,n!=0){
rep(i,m)rep(j,m){
cost[i][j]=(i==j?0:INF);
tim[i][j]=(i==j?0:INF);
}
rep(i,n){
int a,b,c,t;
cin>>a>>b>>c>>t;
a--;b--;
cost[a][b]=cost[b][a]=c;
tim[a][b]=tim[b][a]=t;
}
int k;
cin>>k;
rep(i,k){
int p,q,r;
cin>>p>>q>>r;
p--;q--;
int ans;
if(r==0){
ans=bfs(m,p,q,cost);
}else{
ans=bfs(m,p,q,tim);
}
cout<<ans<<endl;
}
}
return 0;
} | 0 |
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int temp=n;
int lastdigit;
int digits=0;
while(n!=0){
lastdigit=n%10;
n/=10;
digits++;
}
int result=0;
while(digits){
result*=10;
digits--;
result+=lastdigit;
}
if(result>=temp){
cout<<result;
}
else
{
cout<<(result+111);
}
} | #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
int next = n / 100 * 111;
if (next < n) {
next += 111;
}
cout << next << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};
void printv(vint &v){
for(auto e:v) cout<<e<<" ";
cout<<endl;
}
// 繰り返し二乗法
ll power(ll a, ll b){
if(a==1)return a;
// if(a==0)re
ll res=1;
while(b>0){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
const int MAX=2100000;
ll fact[MAX], fact_inv[MAX];
void init_fact(ll n){
fact[0]=1;
// 階乗の計算
for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
fact_inv[n]=power(fact[n], MOD-2);
// 逆元の計算
for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}
ll comb(ll n, ll r){
return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
ll perm(ll n, ll r){
return (fact[n]*fact_inv[n-r])%MOD;
}
int main() {
cout<<fixed<<setprecision(10);
ll k; cin>>k;
ll n = 50;
ll x,y;
x = k/n;
y = k%n;
// ll a_base = (x+1)*n - 1 - y;
ll a_base = ( n - 1 ) + x - y;
vint ans(n, a_base);
rep(i,y){
ans[i] += n - (i+1) + 2;
}
cout << n <<endl;
for(auto e:ans) cout<<e<<" ";
cout<<endl;
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
int main() {
long k;
cin >> k;
long q = k / 50, r = k % 50;
cout << 50 << '\n';
for (long i=0; i<50; i++)
cout << q + i - r + (i < r ? 51 : 0) << (i < 49 ? ' ' : '\n');
return 0;
} | 1 |
#include<stdio.h>
#include<string.h>
void haichi(void);
void Block(int,int);
int c,d,x,y,xg,yg,M,Flag;
int MAP[101][101],MF[101][101];
int main(void)
{
int w,h,xs,ys,n;
while(1){
Flag=0;
memset(MAP,0,sizeof(MAP));
memset(MF,0,sizeof(MF));
scanf("%d %d",&w,&h);
if(w == 0 && h == 0) break;
scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %d %d %d",&c,&d,&x,&y);
haichi();
}
/*for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
printf("%d",MAP[i][j]);
}
printf("\n");
}*/
M = MAP[ys][xs];//
if(MAP[ys][xs] == MAP[yg][xg])
Block(xs,ys);
if(Flag==1)
printf("OK\n");
else
printf("NG\n");
}
return 0;
}
void haichi(void)
{
if(d==0){
MAP[y][x]=c;MAP[y][x+1]=c;MAP[y][x+2]=c;MAP[y][x+3]=c;
MAP[y+1][x]=c;MAP[y+1][x+1]=c;MAP[y+1][x+2]=c;MAP[y+1][x+3]=c;
}
else if(d==1){
MAP[y][x]=c;MAP[y][x+1]=c;
MAP[y+1][x]=c;MAP[y+1][x+1]=c;
MAP[y+2][x]=c;MAP[y+2][x+1]=c;
MAP[y+3][x]=c;MAP[y+3][x+1]=c;
}
}
void Block(int X,int Y)
{
MF[Y][X] = 1;
//printf("%d",M);
if(X == xg && Y == yg)
Flag = 1;
if(MAP[Y-1][X] == M && MF[Y-1][X] == 0) Block(X,Y-1); //???
if(MAP[Y+1][X] == M && MF[Y+1][X] == 0) Block(X,Y+1); //???
if(MAP[Y][X-1] == M && MF[Y][X-1] == 0) Block(X-1,Y); //???
if(MAP[Y][X+1] == M && MF[Y][X+1] == 0) Block(X+1,Y); //???
} | #include<iostream>
using namespace std;
#define MAX 100
#define BLANK 0
#define LONG 4
#define SHORT 2
#define HORIZONTAL 0
#define VERTICAL 1
#define VISITED 9
int field[MAX+2][MAX+2];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void rec(int x,int y,int c)
{
int i;
if(field[x][y]!=c)return;
field[x][y]=VISITED;
for(i=0;i<4;i++)rec(x+dx[i],y+dy[i],c);
return;
}
int main()
{
int w,h,xs,ys,xg,yg,n,c,d,x,y;
int i,j;
while(cin>>w>>h>>xs>>ys>>xg>>yg>>n,w|h){
for(j=1-1;j<=h+1;j++)for(i=1-1;i<=w+1;i++)field[i][j]=BLANK;
while(n-->0){
cin>>c>>d>>x>>y;
if(d==HORIZONTAL)
for(i=0;i<LONG;i++)for(j=0;j<SHORT;j++)field[x+i][y+j]=c;
else
for(i=0;i<SHORT;i++)for(j=0;j<LONG;j++)field[x+i][y+j]=c;
}
if(field[xs][ys]!=BLANK)rec(xs,ys,field[xs][ys]);
puts(field[xg][yg]==VISITED?"OK":"NG");
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
string a;
cin>>a;
if(a.at(0)!='A'){
cout<<"WA"<<endl;
return 0;
}
for(ll i=2;i<a.size()-1;i++){
if(a.at(i)=='C'){
a.at(i)='z';
break;
}
if(i==a.size()-2){
cout<<"WA"<<endl;
return 0;
}
}
for(ll i=1;i<a.size();i++){
if(a.at(i)<'a'||a.at(i)>'z'){
cout<<"WA"<<endl;
return 0;
}
}
cout<<"AC"<<endl;
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main(){
string str;
cin >> str;
for(auto it=str.rbegin();it!=str.rend();++it)cout << *it;
cout << endl;
return 0;
} | 0 |
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
int n,k;
int card[16];
int check[16];
set<string> ss;
string tos(int a){
char str[100];
int i=0;
while( a>0 ){
str[i++] = a%10 + '0';
a /= 10;
}
str[i] = 0;
string s = string(str);
return string(s.rbegin(), s.rend());
}
void solve(int cnt, string str){
//printf("%d , %s\n",cnt,str.c_str());
if( cnt==0 ){
ss.insert(str);
return;
}
for(int i=0; i<n; i++)if( !check[i] ){
check[i] = 1;
solve(cnt-1, str + tos(card[i]));
check[i] = 0;
}
return;
}
int main(){
while(scanf("%d%d",&n,&k),n|k){
ss.clear();
rep(i,n)scanf("%d",&card[i]);
solve(k,"");
cout << ss.size() << endl;
}
return 0;
} | #include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#pragma warning (disable: 4996)
using namespace std;
int dat[10] = { 0,2,5,5,4,5,6,3,7,6 };
int N, M, A[1 << 18];
int dp[1 << 18];
int main() {
cin >> N >> M;
for (int i = 1; i <= M; i++) cin >> A[i];
for (int i = 0; i <= N; i++) dp[i] = -(1 << 30);
dp[0] = 0;
for (int i = 0; i <= N; i++) {
for (int k = 1; k <= M; k++) dp[i + dat[A[k]]] = max(dp[i + dat[A[k]]], dp[i] + 1);
}
int val = N; string S = "";
while (val > 0) {
int r = 0;
for (int i = 1; i <= M; i++) {
if (val >= dat[A[i]] && dp[val] - 1 == dp[val - dat[A[i]]]) r = max(r, A[i]);
}
val -= dat[r]; S += ('0' + r);
}
//reverse(S.begin(), S.end());
cout << S << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main() {
bool A=0;
char ch,ch_;
cin>>ch;
ch_=ch;
while((cin>>ch)!=0) {
if(ch_=='A'&&ch=='C') {
cout<<"Yes";
return 0;
}
ch_=ch;
}
cout<<"No";
return 0;
} | #pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma region UnionFind
struct UnionFind
{
vector<int> par;
UnionFind(int n) : par(n, -1) {}
void init(int n) { par.assign(n, -1); }
int root(int x)
{
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
bool merge(int x, int y)
{
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x)
{
return -par[root(x)];
}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
if (a%b == 0)return b;
return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
#pragma endregion
#pragma endregion
int main()
{
string s; cin >> s;
rep(i, s.size() - 1)if (s.substr(i, 2) == "AC")
{
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
} | 1 |
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (int)3e5 + 17;
const int mod = (int)1e9 + 7;
const int OFFSET = 5;
int n, suff[MAXN];
string s;
void read()
{
cin >> s;
n = s.size();
}
int dp[MAXN][10][4];
int rec(int pos, int len, int bd)
{
if(bd > 2)
{
if(bd % 2 == 0) len += (bd - 2), bd = 2;
if(bd % 2 == 1) len += (bd - 1), bd = 1;
}
if(bd < 0) bd = 0;
if(len > 4) len = 4;
if(pos == n)
{
if(len > 0) return 1;
return 0;
}
int &memo = dp[pos][len + OFFSET][bd];
if(memo != -1) return memo;
memo = 0;
if(s[pos] == '1' || s[pos] == '?') memo = (memo + rec(pos + 1, len + 1, bd - 1)) % mod;
if(s[pos] == '0' || s[pos] == '?') memo = (memo + rec(pos + 1, len - 1, bd + 1)) % mod;
return memo;
}
void solve()
{
suff[n] = 1;
for(int i = n - 1; i >= 0; i--)
{
suff[i] = suff[i + 1];
if(s[i] == '?') suff[i] = (2ll * suff[i + 1]) % mod;
}
memset(dp, -1, sizeof(dp));
cout << rec(0, 0, 0) << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define MAXN 1000005
#define P 998244353
template <typename T> void read(T &x) {
x = 0; int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
long long fac[MAXN], inv[MAXN];
void update(long long &x, long long y) {
x = (x + y) % P;
}
long long power(long long x, long long y) {
if (y == 0) return 1;
long long tmp = power(x, y / 2);
if (y % 2 == 0) return tmp * tmp % P;
else return tmp * tmp % P * x % P;
}
long long getc(long long x, long long y) {
return fac[x] * inv[y] % P * inv[x - y] % P;
}
int main() {
int n, m;
read(n), read(m);
if (n < m) swap(n, m);
fac[0] = 1;
for (int i = 1; i <= n + m; i++)
fac[i] = fac[i - 1] * i % P;
inv[n + m] = power(fac[n + m], P - 2);
for (int i = n + m - 1; i >= 0; i--)
inv[i] = inv[i + 1] * (i + 1) % P;
long long ans = 0;
for (int i = 1; i <= m; i++)
update(ans, getc(2 * i, i) * getc(n + m - 2 * i, m - i));
ans = ans * power(getc(n + m, m) * 2 % P, P - 2) % P;
update(ans, n);
cout << ans << endl;
return 0;
} | 0 |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;
template<class T, class S> inline bool chmax(T &a, const S &b){
if(a < b){
a = b; return true;
}
return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
if(b < a){
a = b; return true;
}
return false;
}
int main(){
int N, a; std::cin >> N;
//dp[i][j] := i-4(0-order)文字まで見て j=(取らない)-(取った)+1
std::vector<std::vector<long long>> dp(N+4, std::vector<long long>(3, 0));
for(int i(4), i_len(N+4); i < i_len; ++i){
std::cin >> a;
if(i & 1)
dp[i][1] = std::max(dp[i-1][0], std::max(dp[i-2][1], dp[i-3][0]) + a);
else{
dp[i][0] = dp[i-2][0] + a;
if(i > 4)
dp[i][2] = std::max(dp[i-1][1], std::max({dp[i-2][2], dp[i-3][1], dp[i-4][0]}) + a);
}
}
std::cout << dp[N+3][(N & 1) + 1] << std::endl;
return 0;
}
| //by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
char s[100000];
int it,len;
fastio(){it=len=0;}
inline char get()
{
if(it<len)return s[it++];it=0;
len=fread(s,1,100000,stdin);
if(len==0)return EOF;else return s[it++];
}
bool notend()
{
char c=get();
while(c==' '||c=='\n')c=get();
if(it>0)it--;
return c!=EOF;
}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
ll r=0;bool ng=0;char c;c=_buff.get();
while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
if(c=='-')ng=1,c=_buff.get();
while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
if(x<0)putchar('-'),x=-x;
register short a[20]={},sz=0;
while(x)a[sz++]=x%10,x/=10;
if(sz==0)putchar('0');
for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const double eps=1e-7;
const double pi=acos(-1);
bool is0(double x){return x>-eps&&x<eps;}
struct point
{
double x,y;
point(double _x=0,double _y=0){x=_x;y=_y;}
point operator+(const point &t)const{return point(x+t.x,y+t.y);}
point operator-(const point &t)const{return point(x-t.x,y-t.y);}
point operator*(const point &t)const{return point(x*t.x-y*t.y,x*t.y+y*t.x);}
point operator*(const double &t)const{return point(x*t,y*t);}
point operator/(const double &t)const{return point(x/t,y/t);}
point operator-()const{return point(-x,-y);}
double len()const{return sqrt(x*x+y*y);}
point operator/(const point &t)const{return point(x*t.x+y*t.y,-x*t.y+y*t.x)/t.len()/t.len();}
double det(const point &t)const{return x*t.y-y*t.x;}
double dot(const point &t)const{return x*t.x+y*t.y;}
double len2()const{return x*x+y*y;}
point unit()const{return (*this)/len();}
bool operator<(const point &t)const{return is0(x-t.x)?y<t.y:x<t.x;}
bool operator==(const point &t)const{return is0(x-t.x)&&is0(y-t.y);}
void out(){cerr<<x<<","<<y<<endl;}
double rad()const{return atan2(y,x);}
point conj()const{return point(x,-y);}
};
point a[111];
int n;
int main()
{
geti(n);
for(int i=1;i<=n;i++)
{
int x,y;
getii(x,y);
a[i].x=x;a[i].y=y;
}
for(int i=1;i<=n;i++)
{
vector<pair<double,int> > v;
int cur=0;
for(int j=1;j<=n;j++)
{
if(i==j)continue;
point p=(a[j]-a[i])*point(0,-1);
point q=(a[j]-a[i])*point(0,1);
double l=p.rad();
double r=q.rad();
v.PB(MP(l,1));
v.PB(MP(r,-1));
if(l>r)cur++;
}
v.PB(MP(-acos(-1),0));
v.PB(MP(acos(-1),0));
sort(v.begin(),v.end());
double sum=0;
for(int j=0;j+1<v.size();j++)
{
cur+=v[j].SS;
if(cur==0)
{
sum+=v[j+1].FF-v[j].FF;
}
}
cout<<fixed<<setprecision(10)<<sum/acos(-1)/2<<endl;
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
const int mod = (int) 1e9+7;
void __print() {cerr << "]\n";}
template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}
#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)
int n;
int a[51];
int f(int k)
{
int ans = 0;
for(int A = 0; A <= n; A++) {
for(int B = 0; B <= n; B++) {
if(A+B > k || A+B > n) continue;
int sum = 0;
vector<int> v;
for(int i = 0; i < A; i++) {
v.push_back(a[i]);
sum += a[i];
}
for(int i = n-1; i >= n - B; i--) {
v.push_back(a[i]);
sum += a[i];
}
sort(v.rbegin(), v.rend());
ans = max(ans, sum);
for(int i = 0; i < k-A-B && v.size(); i++) {
sum -= v.back();
ans = max(ans, sum);
v.pop_back();
}
}
}
return ans;
}
int main()
{
int k;
scanf("%d%d", &n, &k);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
int ans = 0;
for(int i = 0; i <= k; i++) {
ans = max(ans, f(i));
}
printf("%d\n", ans);
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }
const int MAXN = 1010;
const int MAXV = MAXN*(MAXN-1)/2;
vint to[MAXV];
int id[MAXN][MAXN];
bool visited[MAXV];
int dp[MAXV];
bool calculated[MAXV];
int dfs(int a){
if(visited[a]){
if(!calculated[a]){
return -1;
}
return dp[a];
}
visited[a] = true;
dp[a] = 1;
for(int p:to[a]){
int u = dfs(p);
if(u == -1){
return -1;
}
dp[a] = max(dp[a],u+1);
}
calculated[a] = true;
return dp[a];
}
int toID(int a,int b){
if(a < b) swap(a,b);
return id[a][b];
}
signed main(){
int n;
cin >> n;
vvint A(n,vint(n-1));
rep(i,0,n){
rep(j,0,n-1){
cin >> A[i][j];
A[i][j]--;
}
}
int v = 0;
rep(i,0,n){
rep(j,0,n){
if(i > j){
id[i][j] = v;
v++;
}
}
}
rep(i,0,n){
rep(j,0,n-1){
A[i][j] = toID(i,A[i][j]);
}
}
rep(i,0,n){
rep(j,0,n-2){
to[A[i][j+1]].push_back(A[i][j]);
}
}
int ans = 0;
rep(i,0,v){
int res = dfs(i);
if(res == -1){
cout << -1 << endl;
return 0;
}
ans = max(ans,res);
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9+7 ;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n ;
cin >> n ;
vector<pair<ll,ll>> A(n);
for(int i = 0 ; i < n ; ++i){
cin >> A[i].first >> A[i].second ;
}
auto comp = [&](pair<ll,ll>& a, pair<ll,ll>& b){
return a.first + a.second < b.first + b.second ;
};
sort(A.begin(),A.end(),comp);
vector<vector<ll>> dp (n+1 , vector<ll> (n + 1, 1e14));
dp[0][0] = 0 ;
for(int i = 1 ; i <= n ; ++i){
for(int j = 0 ; j <= n ; ++j){
if (j == 0){
dp[i][j] = min(dp[i][j] , dp[i-1][j]) ;
continue ;
}
dp[i][j] = dp[i-1][j];
// if(i == 1 && j == 1){
// cout <<"&&&&&&&&&&&&&&&77"<<"\n";
// cout << dp[i-1][j] << "\n";
// cout << dp[i-1][j-1] << "\n";
// cout <<A[i-1].first <<" , "<< A[i-1].second << "\n";
// cout <<"%%%%%%%%%%%%%%%%%%"<<"\n";
// }
if(A[i-1].first >= dp[i-1][j-1]){
dp[i][j] = min (dp[i][j], A[i-1].second + dp[i-1][j-1] );
}
}
}
// cout <<"dp array :: "<< "\n";
// for(int i = 1 ; i <= n ;++i){
// for(int j = 1 ; j <= n ;++j){
// cout << dp[i][j] << " ";
// }
// cout << "\n";
// }
for(int j = n ; j >= 0 ;--j){
if (dp[n][j] != 1e14){
cout << j << "\n";
break;
}
}
return 0;
}
| #include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");
vii v;
int n,dp[5000][5001];
int f(int i,int k){// f(i,j) min price when j items taken and i items included
if(k<0)return INF;
if(i==-1){
if(k>0)return INF;
return 0;
}
int &ans=dp[i][k];
if(ans!=-1)return ans;
ans=INF;
int picheka=f(i-1,k-1);
if(picheka<=v[i].first)ans=min(ans,picheka+v[i].second);
ans=min(ans,f(i-1,k));
return ans;
}
signed main(){
FASTER;
memset(dp,-1,sizeof dp);
cin>>n;
v=vii(n);cin>>v;
sort(all(v),[](const pii &a,const pii &b){return a.first+a.second<b.first+b.second;});
for(int i=n;i>=0;i--){
if(f(n-1,i)!=INF){
cout<<i;
return 0;
}
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
ll l, r;
cin >> l >> r;
if (r - l + 1 >= 2019)
cout << 0 << endl;
else {
ll ans = INF;
repl(i, l, r + 1) repl(j, i + 1, r + 1) ans = min(ans, i * j % 2019);
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
class Solve {
public:
Int modmul(Int a, Int b) {
return a * b % MOD;
}
void solve() {
Int N;
string S;
cin >> N >> S;
N *= 2;
vector<int> LR(N);
if (S[0] == 'W' || S.back() == 'W') {
cout << 0 << endl;
return;
}
LR[0] = 0;
for (int i = 1; i < N; ++i) {
if (S[i - 1] == S[i]) {
LR[i] = 1 - LR[i - 1];
} else {
LR[i] = LR[i - 1];
}
}
Int ans = 1;
Int tapi = 0;
for (int i = 0; i < N; ++i) {
if (LR[i] == 0) {
tapi++;
} else {
ans = modmul(ans, tapi);
tapi--;
}
}
if (tapi != 0) {
cout << 0 << endl;
return;
}
for (int i = 0; i < N / 2; ++i) {
ans = modmul(ans, i + 1);
}
cout << ans << endl;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
Solve().solve();
return 0;
}
| 0 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool AC = true;
if(s[0] != 'A') AC = false;
int count = 0;
for(int i=2; i<s.size()-1; i++) {
if(s[i]=='C') count++;
else if (isupper(s[i])) AC = false;
if(i==s.size()-2 && count != 1) AC = false;
}
for(int i=1; i<s.size(); i++) {
if(i==1 || i==s.size()-1) {
if(isupper(s[i])) AC = false;
}
}
if(AC) cout << "AC" << endl;
else cout << "WA" << endl;
return 0;
} | #include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
string input;
cin >> input;
regex pattern("^A[a-z]+C[a-z]+$");
if (regex_match(input, pattern))
{
cout << "AC" << endl;
}
else
{
cout << "WA" << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;
int a[20][20];
int ans;
bool inside(int x, int y) {
return 0 <= x && x < H && 0 <= y && y < W;
}
void dfs(int x, int y, int c) {
if (c > 10) return;
rep(k, 4) {
int nx = x + dx[k], ny = y + dy[k];
if (!inside(nx, ny)) continue;
if (a[nx][ny] == 1) continue;
while (true) {
if (!inside(nx, ny)) break;
if (a[nx][ny] == 1) {
a[nx][ny] = 0;
dfs(nx - dx[k], ny - dy[k], c + 1);
a[nx][ny] = 1;
break;
}
else if (a[nx][ny] == 3) {
ans = min(ans, c);
break;
}
nx += dx[k], ny += dy[k];
}
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
while (cin >> W >> H, H) {
int sx, sy;
rep(i, H) rep(j, W) {
cin >> a[i][j];
if (a[i][j] == 2) {
sx = i, sy = j;
}
}
ans = INF;
dfs(sx, sy, 1);
cout << (ans == INF ? -1 : ans) << endl;
}
} | // ALDS1_13_A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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;}
namespace you {
std::string to_string(char val) {
return std::string(1, val);
// return std::string{val};
// you::to_string(char)
}
}
vector<int> x;
vector<int> y;
vector<int> vx={-1,1,1,-1};
vector<int> vy={-1,1,-1,1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int k;
cin>>k;
rep(i,k){
int xx,yy;
cin>>xx>>yy;
x.push_back(xx);
y.push_back(yy);
}
vector<int> kind(8);
rep(i,8) kind[i]=i;
do{
vector<vector<bool>> ban(8,vector<bool>(8,false)); //falseが. trueがQ
rep(i,k){
ban[x[i]][y[i]]=true;
}
int numq=k;
rep(i,8){
if(ban[i][kind[i]]==false){
ban[i][kind[i]]=true;
numq+=1;
}
}
int okq=0;
if(numq!=8) continue; //Qを8個以上おいてるときは無視
else{
//cout<<kind<<endl;
rep(i,8){ //8個のQについてみる。
int ny=i,nx=kind[i];
bool flag=true;
rep(j,4){ //左右上下斜め方向の確認
int newx=nx+vx[j],newy=ny+vy[j];
while(0<=newx&&newx<=7&&0<=newy&&newy<=7){
if(ban[newy][newx]==true){
flag=false;
break;
}
newx+=vx[j];
newy+=vy[j];
}
if(!(flag)) break;
}
if(flag) okq+=1;
}
}
//cout<<okq<<endl;
if(okq==8) break;
}while(next_permutation(all(kind)));
//cout<<kind<<endl;
vector<vector<bool>> ans(8,vector<bool>(8,false));
rep(i,8) ans[i][kind[i]]=true;
rep(i,8){
rep(j,8){
if(ans[i][j]) cout<<"Q";
else cout<<".";
}
cout<<endl;
}
return 0;
}
| 0 |
#include <cstdio>
#include <cmath>
#define buf 10000
using namespace std;
int k=0;
int B[buf];
void Answer(int n);
int PrimeNumber(int n);
int main(void){
int i,n;
char str[buf];
for(i=2;i<buf;i++)
PrimeNumber(i);
for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
sscanf(str,"%d",&n);
if(n==0) break;
Answer(n);
}
return 0;
}
void Answer(int n){
int i,j;
for(i=0;i<k;i++){
if(B[i]>n)
break;
}
for(j=i-1;j>=0;j--){
if(B[j]-B[j-1]==2){
printf("%d %d\n",B[j-1],B[j]);
break;
}
}
}
int PrimeNumber(int n){
int i,c;
if(n==2){
B[k]=n;
k++; return 0;
}
if(n<2 || n%2==0)
return 0;
c=sqrt(n);
for(i=3;i<=c;i+=2){
if(n%i==0)
return 0;
}
B[k]=n;
k++; return 0;
} | #include<iostream>
using namespace std;
bool isp[10000];
main()
{
isp[0]=isp[1]=1;
for(int i=2;i<=100;i++)
{
if(isp[i])continue;
for(int j=i*i;j<=10000;j+=i)isp[j]=1;
}
int n;
while(cin>>n,n)
{
while(isp[n]||isp[n-2])n--;
cout<<n-2<<" "<<n<<endl;
}
}
| 1 |
#include <iostream>
using namespace std;
int main(void){
int n,a[100];
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cout << a[n];
for(int i = n-1; i >= 1; i--){
cout << " " << a[i];
}
cout << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;
int main(){
ll N;
cin >> N;
multiset<string> mp;
string s;
string S[N];
rep(i, N){
cin >> s;
S[i] = s;
mp.insert(s);
}
ll M;
cin >> M;
multiset<string> mn;
rep(i, M){
cin >> s;
mn.insert(s);
}
ll ans = 0;
ll count;
rep(i, N){
count = mp.count(S[i]) - mn.count(S[i]);
ans = max(ans, count);
}
cout << ans << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";
const ll inf = 1e18;
ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}
int main(){
fast;
#ifndef ONLINE_JUDGE
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif
ll n, x;
cin>>n>>x;
ll a[n];
scan(a, 0, n);
ll ans = 0;
forn(i, 1, n){
if(a[i]+a[i-1]>x){
ll z = a[i-1]+a[i]-x;
ans+=z;
if(z>=a[i]){
a[i] = 0;
z-=a[i];
a[i-1]-=z;
} else {
a[i]-=z;
}
}
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;
int main() {
int N, Q;
string S;
cin >> N >> Q >> S;
vector<int> V(N,0);
for (int i=1; i<N; i++) {
if (S[i-1]=='A' && S[i]=='C') {
V[i]=V[i-1]+1;
}
else {
V[i]=V[i-1];
}
//cout << V[i]<< endl;
}
int l, r;
for (int i=0; i<Q; i++) {
cin >> l >> r;
l--;
r--;
cout << V[r]-V[l] << endl;
}
} | 0 |
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出,オーバーフローする入力を投げるとよい
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
bool comp(pair<ll, ll> a, pair<ll , ll> b) {
// 基本はfirstで比較
if(a.first != b.first){
// return a.first < b.first; // 昇順
return a.first > b.first; // 降順
}
// それ以外はsecondで比較
if(a.second != b.second){
return a.second > b.second;
}else{
// どちらも同じ
return true;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,d,m,n,maxi=0,f=0,mini=INF,sum=0;
string str,stra="CODEFESTIVAL2016";
ll k;
ll w,x,y;
ll h;
cin>>n;
vector<ll> v(n);
rep(i,n) cin>>v[i];
map<ll,ll> m1;
map<ll,ll> m2;
set<ll> s1;
set<ll> s2;
rep(i,n){
if(i%2) {
s1.insert(v[i]);
m1[v[i]]++;
}else{
s2.insert(v[i]);
m2[v[i]]++;
}
}
vector<pair<ll,ll>> p1(s1.size()+1);
vector<pair<ll,ll>> p2(s2.size()+1);
p1[s1.size()]=make_pair(0,-1);
p2[s2.size()]=make_pair(0,-2);
ll i=0;
for(auto itr=s1.begin();itr!=s1.end();itr++,i++){
p1[i]=make_pair(m1[*itr],*itr);
}
i=0;
for(auto itr=s2.begin();itr!=s2.end();itr++,i++){
p2[i]=make_pair(m2[*itr],*itr);
}
sort(all(p1),comp);
sort(all(p2),comp);
if(p1[0].second==p2[0].second){
cout<<n-max(p1[1].first+p2[0].first,p1[0].first+p2[1].first)<<endl;
}else{
cout<<n-(p1[0].first+p2[0].first)<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n; cin >> n;
if (n == 2) {
int o, e; cin >> o >> e;
if (o == e) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
const int p = n / 2;
const int z = 100001;
vector<int> o_num(z, 0), e_num(z, 0);
for (int i = 0; i < n; i++) {
int v; cin >> v;
if (i % 2 == 0) o_num[v]++;
else e_num[v]++;
}
int o_firstCnt = 0;
int o_secondCnt = 0;
int o_firstCntValue = 0;
int e_firstCnt = 0;
int e_secondCnt = 0;
int e_firstCntValue = 0;
for (int i = 0; i < z; i++) {
if (o_firstCnt <= o_num[i]) {
o_secondCnt = o_firstCnt;
o_firstCnt = o_num[i];
o_firstCntValue = i;
}
else {
o_secondCnt = max(o_secondCnt, o_num[i]);
}
if (e_firstCnt <= e_num[i]) {
e_secondCnt = e_firstCnt;
e_firstCnt = e_num[i];
e_firstCntValue = i;
}
else {
e_secondCnt = max(e_secondCnt, e_num[i]);
}
}
int ans;
if (o_firstCntValue != e_firstCntValue) {
ans = n - o_firstCnt - e_firstCnt;
}
else { // o_firstCntValue == e_firstCntValue
ans = min(n - o_secondCnt - e_firstCnt, n - o_firstCnt - e_secondCnt);
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;
int N, K;
vector<int> D;
void dfs(int n) {
bool flag = false;
int tmp = n;
while (tmp > 0) {
for (int i = 0; i < K; i++) {
if (tmp % 10 == D[i]) {
flag = true;
break;
}
}
if (flag == true) break;
tmp /= 10;
}
if (flag == true) dfs(n + 1);
if (flag == false) cout << n << endl;
}
int main() {
cin >> N >> K;
for (int i = 0; i < K; i++) {
int d;
cin >> d;
D.push_back(d);
}
dfs(N);
return 0;
} | #include <bits/stdc++.h>
#define INF 1e9
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
void solve() {
int N,K;
cin >> N >> K;
set<int> D;
REP(_,K) {
int d;
cin >> d;
D.insert(d);
}
FOR(val,N,100000) {
string s = to_string(val);
bool ok = true;
for(const auto &it: s) if(D.count(((int)it-'0'))) ok = false;
if(!ok) continue;
cout << val << endl;
return;
}
}
int main() {
solve();
return 0;
} | 1 |
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
int main() {
ll a,b;
cin >> a >> b;
vector<ll> ay;
vector<ll> by;
for(ll i = 1; i <= sqrt(a);i++){
if(a%i == 0){
ay.push_back(i);
if(i != a/i){
ay.push_back(a/i);
}
}
}
for(ll i = 1; i <= sqrt(b);i++){
if(b%i == 0){
by.push_back(i);
if(i != b/i){
by.push_back(b/i);
}
}
}
//cout << ay.size() << " " << by.size() << endl;
vector<ll> kys;
for(int i = 0;i<ay.size();i++){
for(int j = 0;j<by.size();j++){
if(ay[i]==by[j]){
kys.push_back(ay[i]);
//cout << ay[i] << " " << by[j]<< endl;
}
}
}
int res = 0;
int flg = 0;
sort(kys.begin(),kys.end(),greater<ll>());
for(int i = 0;i<kys.size();i++){
flg = 0;
for(int j = i+1;j<kys.size();j++){
if(__gcd(kys[i],kys[j]) != 1){
flg = 1;
break;
}
}
if(flg == 0){res++;}
}
cout << res;
} | #include <stdio.h>
int main(void){
int A,B;
scanf ("%d %d",&A,&B);
if (B+2<=A) printf ("%d",A+(A-1));
if (A+2<=B) printf ("%d",B+(B-1));
else {
if (A==B+1||B==A+1||A==B) printf ("%d",A+B);
}
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int cpN = N;
int sum = 0;
while(cpN > 0){
sum += cpN % 10;
cpN /= 10;
}
if(N % sum == 0)cout << "Yes" << endl;
else cout << "No" << endl;
} | #include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;cin>>s;
for(int i=0;i<s.size()-1;i++){
if(s[i] == 'A' && s[i+1] == 'C'){
cout<<"Yes"<<endl;
return 0;
}
}
cout<<"No"<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
ll a[16][16];
ll v[1 << 16]; // value of that submask
ll dp[1 << 16];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n; read(n);
rep(i, 0, n) rep(j, 0, n) read(a[i][j]);
for (int b = 0; b < (1 << n); b++) {
for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if ((b >> i & 1) && (b >> j & 1))
v[b] += a[i][j];
}
dp[0] = 0;
for (int i = 1; i <= n; i++) for (int j = 0; j < (1 << n); j++) if (__builtin_popcount(j) == i) {
dp[j] = v[j];
for (int k = j; k > 0; k = (k - 1) & j) {
chmax(dp[j], dp[j ^ k] + v[k]);
}
}
write(dp[(1 << n) - 1]);
}
| #include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=2e3+5;
char S[maxn];
int s[maxn][maxn],a[maxn][maxn];
int i,j,H,W,ans,h[maxn][maxn],t,q[maxn][2],cnt,len;
int main(){
scanf("%d%d",&H,&W);
fo(i,1,H) {
scanf("%s",S+1);
fo(j,1,W) s[i][j]=S[j]=='#';
}
ans=max(H,W);
if (H==1||W==1) return printf("%d\n",ans),0;
H--,W--;
fo(i,1,H){
cnt=0;
fo(j,1,W){
t=s[i][j]^s[i][j+1]^s[i+1][j]^s[i+1][j+1]^1;
len=h[i][j]=(t)?h[i-1][j]+1:0;
for(;cnt&&q[cnt][0]>len;cnt--) ans=max(ans,(q[cnt][0]+1)*(j-q[cnt-1][1]));
q[++cnt][0]=len,q[cnt][1]=j;
}
for(;cnt;cnt--) ans=max(ans,(q[cnt][0]+1)*(W-q[cnt-1][1]+1));
}
printf("%d\n",ans);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int x[n],i=0;
int z=0;
for (;i<n;i++){
cin>>x[i];
if(z==0&&i>0){
int j=i-1;
if(x[j]==x[i]||x[j-1]==x[i])
z++;
}
}
if(z==0){
sort(x,x+n);
int j=n-1;
int m=n/2+1;
int k=n/2-1;
for (int i=0;i<n/4+2;i++){
if(x[i+1]==x[i]||x[j]==x[j-1]||x[m]==x[m-1]||x[k]==x[k+1]){
z++;
break;
}
else{
j--;
m++;
k--;
}
}
}
if(z==0)
cout<<"YES";
else
cout<<"NO";
return 0;
}
| #include<iostream>
#include<algorithm>
using namespace std;
int p[200000];
int main() {
//C
int n;
cin >> n;
int i;
for (i = 0; i < n; i++) {
cin >> p[i];
}
sort(p, p + n);
for (i = 0; i < n-1; i++) {
if (p[i] == p[i + 1]) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
//D
/*int n, k;
cin >> n >> k;
int i;
for (i = 0; i < n; i++) {
cin >> p[i];
}
int max = 0;
int sum = 0;
for (i = 0; i < k; i++) {
sum = sum + p[i];
}
max = sum;
for (i = k; i < n; i++) {
sum = sum + p[i] - p[i - k];
if (sum > max)max = sum;
}
//cout << max + k << endl;
double f = (double)(((double)max +(double) k) / 2);
printf("%.10f\n", f);
//cout << (max + k) / 2 << endl;
return 0;
*/
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
string str;
int A, B, C, D;
int N[15];
cin >> str;
transform(begin(str), end(str), N, [](char c) {return c - '0'; });
A = N[0];
B = N[1];
C = N[2];
D = N[3];
for (int i=0;i<2;++i) {
for (int j=0;j<2;++j) {
for (int k=0;k<2;++k) {
int ans =0;
string op1 = (i%2==0) ? "+" :"-";
string op2 = (j%2==0) ? "+" :"-";
string op3 = (k%2==0) ? "+" :"-";
if (op1=="+") {
ans =A+B;
}
else {
ans = A-B;
}
if (op2=="+") {
ans +=C;
}
else {
ans -= C;
}
if (op3=="+") {
ans +=D;
}
else {
ans -= D;
}
if (ans==7) {
cout << A<<op1<<B<<op2<<C<<op3<<D<<"="<<7<<endl;
return 0;
}
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
#define fi first
#define se second
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}
int now[4];
char C[4], op[2] = {'+', '-'};
int main(){
for (int i = 0; i < 4; i++){
cin >> C[i];
now[i] = C[i] - '0';
}
for (int i = 0; i < 8; i++){
int val = now[0], num = i;
for (int j = 1; j < 4; j++){
val += pow(-1, num % 2) * now[j];
num /= 2;
}
if (val == 7){
num = i;
cout << now[0];
for (int j = 1; j < 4; j++){
cout << op[num%2] << now[j];
num /= 2;
}
cout << "=7" << endl;
return 0;
}
}
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
cin>>s>>n;
for(int i=0;i<s.size();i+=n)cout<<s[i];
puts("");
} | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author champon
*/
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP
class debug
{
public:
template<typename T> void vdeb(T vec);
template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
template<typename T> void mdeb(T mp);
};
#endif //INCLUDE_DEBUG_HPP
template<typename T> void debug::vdeb(T vec)
{
cout << "#vector set debug" << endl;
for(auto vv : vec) cout << vv << " ";
cout << endl;
}
template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
cout << "#adebug" << endl;
for(int i=0; i<=n; i++) cout << arr[i] << " ";
cout << endl;
}
template<typename T> void debug::mdeb(T mp)
{
cout << "#map pair debug" << endl;
for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;
class BAcrostic {
public:
void solve(std::istream& in, std::ostream& out)
{
string s;
int w;
in >> s >> w;
string res = "";
for(int i=0; i<s.length(); i++){
if(i%w == 0) res += s[i];
}
out << res << endl;
}
};
int main() {
BAcrostic solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 1 |
#include<cstdio>
#include<cstring>
#define N 300010
using namespace std;
int to[8][2]={2,1,
3,5,
4,7,
6,1,
2,2,
5,5,
3,3,
2,1};
char s[N];
int f[N][8];
const int p=1e9+7;
int main()
{
scanf("%s",s);
int n=strlen(s);
f[n][1]=f[n][5]=1;
for(int i=n-1;i>=0;i--)
for(int j=0;j<8;j++)
{
if(s[i]!='1') f[i][j]+=f[i+1][to[j][0]];
if(s[i]!='0') f[i][j]+=f[i+1][to[j][1]];
f[i][j]%=p;
}
printf("%d",f[0][0]);
return 0;
} | #include<cstdio>
#include<cstring>
#define N 300003
#define p 1000000007
inline int mod(int x){return x>p?x-p:x;}
char c[N];int f[8],g[8],i,j,k,n,x;const int a[8]={1,3,5,1,1,7,6,5},b[8]={2,4,6,1,2,2,6,5};
int main()
{
scanf("%s",c+1),n=strlen(c+1),*f=1;
for(i=1;i<=n;i++,memcpy(f,g,32),memset(g,0,32))
{
if(c[i]!=48)for(j=0;j<8;j++)g[b[j]]=mod(g[b[j]]+f[j]);
if(c[i]!=49)for(j=0;j<8;j++)g[a[j]]=mod(g[a[j]]+f[j]);
}
return 0*printf("%d\n",mod(f[2]+f[6]));
} | 1 |
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> divisor(ll n) {
vector<ll> res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (i != n / i) res.push_back(n / i);
}
}
return res;
}
int main() {
ll n;
cin >> n;
auto divs = divisor(n);
sort(divs.begin(), divs.end());
ll left = -1;
ll right = divs.size();
while (right - left > 1) {
ll mid = left + (right - left) / 2;
ll v1 = divs[mid];
ll v2 = n / divs[mid];
if (to_string(v1).size() >= to_string(v2).size())
right = mid;
else
left = mid;
}
ll v1 = divs[right];
ll v2 = n / divs[right];
cout << max(to_string(v1).size(), to_string(v2).size()) << endl;
return 0;
} | #include<stdio.h>
int main(){
char str[15];
scanf("%s", str);
str[3] = '8';
printf("%s\n", str);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int ans=0;
for(int i=n;i!=0;i--){
int a=sqrt(i);
if(a*a==i){
ans=i;
break;
}
}
cout << ans << endl;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;
//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
//
//
//
//
//
//
//
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//
int main() {
ll N; cin >> N;
ll ans = 0;
for (ll i = 1; i*i <= N; ++i) {
ans = max(ans, i*i);
}
out(ans);
return 0;
}
| 1 |
#include<iostream>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,ans=0x3f3f3f3f;
int a[100000+5];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n-m+1;i++){
int j=m+i-1;
ans=min(ans,min(abs(a[i])+abs(a[j]-a[i]),abs(a[j])+abs(a[j]-a[i])));
}
if(ans==0x3f3f3f3f) cout<<0<<endl;
cout<<ans<<endl;
} | /*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007
void solve(int test_case) {//209
int n,k;
cin>>n>>k;
k--;
vi arr(n);
for(int &i:arr)cin>>i;
int mi = INT_MAX;
REP(i,0,n-k-1) {
if(arr[i+k]<0){
mi=min(mi, -arr[i]);
} else if(arr[i]<0) {
mi = min(mi, min(-2*arr[i]+arr[i+k],2*arr[i+k]-arr[i]));
} else mi=min(mi, arr[i+k]);
}
cout<<mi;
}
int main() {
////// FILE BASED IO////
//freopen("wormhole.in", "r", stdin);
//freopen("wormhole.out", "w", stdout);
///////////////
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
REP(i,1,t) {
solve(i);
}
return 0;
}
| 1 |
//bayemirov
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define pb push_back
const int MOD = 1e9 + 7;
const int N = 1e5;
int dp[N][100];
void add(int& x, int y) {
x += y;
if (x > MOD) x -= MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
string a;
cin >> a;
int b;
cin >> b;
int k = a.size();
dp[0][0] = 1;
for (int i = 1; i < k; i++)
for (int j = 0; j < b; j++)
for(int x = 0; x < 10; ++x)
add(dp[i][j], dp[i - 1][((j - x) % b + b) % b]);
int ans = 0;
int sum = 0;
for (int i = 0; i < k; i++) {
for (int j = 0; j < (a[i] - '0'); j++)
add(ans, dp[k - i - 1][((b - sum - j) % b + b) % b]);
sum += (a[i] - '0');
sum %= b;
}
if(sum == 0)
ans++;
cout << ans - 1;
return 0;
}
// ez | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second
void solve(){
int n;
string s;
cin >> n >> s;
vector<int> r(n), g(n), b(n);
r[0] = (s[0]=='R');
for(int i = 1; i < n; ++i) r[i] = r[i-1]+(s[i]=='R');
g[0] = (s[0]=='G');
for(int i = 1; i < n; ++i) g[i] = g[i-1]+(s[i]=='G');
b[0] = (s[0]=='B');
for(int i = 1; i < n; ++i) b[i] = b[i-1]+(s[i]=='B');
ll ans = 0;
for(int i = 0; i < n; ++i){
for(int j = i+1; j < n; ++j){
if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R')){
ans += b[n-1]-b[j];
if(2*j-i<n && s[2*j-i]=='B') --ans;
}
else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')){
ans += g[n-1]-g[j];
if(2*j-i<n && s[2*j-i]=='G') --ans;
}
else if((s[i]=='G' && s[j]=='B') || (s[i]=='B' && s[j]=='G')){
ans += r[n-1]-r[j];
if(2*j-i<n && s[2*j-i]=='R') --ans;
}
}
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
int main() {
int n, m;
cin >> n >> m;
vector<ll> s(n+1);
rep(i,n) {
ll a;
cin >> a;
s[i+1] = (s[i] + a)%m;
}
ll ans = 0;
map<int,ll> mp;
for (int i = 0; i <= n; i++) {
ans += mp[s[i]];
mp[s[i]]++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
int main(){
ll N,M;
cin >> N >> M;
vector<ll> vec(N + 1);
vec[0] = 0;
rep(i,N){
cin >> vec[i + 1];
}
rep(i,N){
vec[i + 1] += vec[i];
}
rep(i,N + 1){
vec[i] %= M;
}
sort(all(vec));
ll ans = 0;
ll count = 1;
vec.push_back(-1);
rep(i,N + 1){
if (vec[i + 1] == vec[i]) count++;
else{
ans += (count - 1) * count / 2;
count = 1;
}
}
cout << ans << endl;
} | 1 |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
for (auto i = first;i != last;i++){
cin >> (*i);
}
}
template<class itr> void array_output(itr start,itr goal){
string ans = "",k = " ";
for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
if (!ans.empty()) ans.pop_back();
PRINT(ans);
}
ll gcd(ll a, ll b) {
return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2000005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll h,w;
cin >> h >> w;
vector<string> grid(h+2);
string s = "";
rep(i,w+2) s += '.';
grid[0] = s;
grid[h+1] = s;
rep(i,h){
cin >> grid[i+1];
grid[i+1] = '.'+grid[i+1]+'.';
}
rep(i,1,h+1){
rep(j,1,w+1){
bool out = 1;
if (grid[i][j] == '#'){
rep(k,4){
ll xn = i+nx[k];
ll yn = j+ny[k];
if (grid[xn][yn] == '#') out = 0;
}
if (out){
PRINT("No");
return 0;
}
}
}
}
PRINT("Yes");
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
ll n,k;
cin >> n >> k;
vector<ll> a(n);
rep(i,n){
cin >> a.at(i);
}
ll i,sum=0,mini=1e9+7;
for(i=0;i<=n-k;i++){
sum=a.at(i+k-1)-a.at(i);
if(a.at(i+k-1)>0 && a.at(i)<0){
ll p=min(a.at(i+k-1),abs(a.at(i)));
sum+=p;
}else{
sum=max(abs(a.at(i+k-1)),abs(a.at(i)));
}
mini=min(mini,sum);
}
cout << mini;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
int a , b;
cin >> a >> b;
int c = 1 , ans = 0;
while(c<b){
c--;
c += a;
ans++;
}
cout<<ans;
} | #include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define pb push_back
#define F first
#define S second
using namespace std;
ll tako(ll a,ll b)
{
if(a>=b)
return 1;
return 1+tako(a,b-a+1);
}
int main()
{
ll a,b;
cin >> a >> b;
if(b==1)
cout << "0";
else
cout << tako(a,b);
return 0;
} | 1 |
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,x,y,ans;
void solve()
{
cin>>n>>m>>x>>y;vector<ll> ar(n),arr(m);
for(int i=0;i<n;i++)
cin>>ar[i];
sort(ar.begin(),ar.end());
for(int i=0;i<m;i++)
cin>>arr[i];
sort(arr.begin(),arr.end());
bool flag=0;
if(x>ar[n-1]||y<arr[0])
{cout<<"War"<<endl;return;}
for(int i=x;i<=y;i++)
{
if(i>ar[n-1]&&i<=arr[0])
{flag=1;break;}
}
if(flag)
cout<<"No War"<<endl;
else
cout<<"War"<<endl;
}
void solve2()
{
cin>>n;ans=0;map<ll,ll>mp;
for(int i=0;i<n;i++)
{
ll a;cin>>a;mp[a]++;
}
for(auto it:mp)
{
ans=max(ans,it.second);
}
cout<<ans<<endl;
}
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
//int t;cin>>t;while(t--)
{
solve();
}
return 0;
}
| // J'aime
// Chemise Blanche
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl
void MAIN() {
int n, m, x, y;
cin >> n >> m >> x >> y;
vector<int> a(n), b(m);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
sort(all(a));
sort(all(b));
if (a.back() < b.front() && a.back() < y && b.front() > x) cout << "No War" << '\n';
else cout << "War" << '\n';
}
signed main() {
#ifdef _DEBUG
// freopen("in" , "r", stdin );
// freopen("out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) MAIN();
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<int, ii>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fi first
#define se second
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
// const int N = ;
void solve() {
int T = 1;
#ifdef multicase
cin >> T;
#endif
for(int tc = 1, n; tc <= T; tc++) {
cin >> n;
cout << n + n * n + n * n * n << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
} | # include<iostream>
# include<math.h>
using namespace std;
int main()
{
int a,b;
cin>>a;
b=pow(a,1)+pow(a,2)+pow(a,3);
cout<<b<<"\n";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()
ll ts = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll x, y, ans = 0;
cin >> x >> y;
if (x == 1) {
ans += 300000;
}
else if (x == 2) {
ans += 200000;
}
else if (x == 3) {
ans += 100000;
}
if (y == 1) {
ans += 300000;
}
else if (y == 2) {
ans += 200000;
}
else if (y == 3) {
ans += 100000;
}
if (x == 1 && y == 1) {
ans += 400000;
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
using namespace std;
string repeat(string s, int n) {
string s1 = "";
for (int i=0; i<n;i++)
s1+=s;
return s1;
}
string getString(char x) {
string s(1, x);
return s;
}
void optimizeIO(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int gcd(int a, int b){
if (a == 0) return b;
return gcd(b % a, a);
}
void solve(){
int n,m;
cin>>n>>m;
set<int> s1;
rep(i,2,sqrt(m)+1){
if(m%i==0) s1.insert(i);
if(m%i==0 && m%(m/i)==0) s1.insert(m/i);
}
s1.insert(m);
s1.insert(1);
for(auto i:s1){
if(i>=n){
cout<<m/i<<endl;
return;
}
}
}
int main(){
optimizeIO();
// tc
{ solve();
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>; using Vi = vector<long long int>;
using P = pair<int, int>; using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
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; }
///////////////////////////////////////////////////////////////////////////////////
int digit[50];
void solve(){
int n;
cin >> n;
if(n==0){
print(0);
return;
}
bool plus=true;
if(n<0) {
plus=false;
n=-n;
}
int ctr=0;
while(n>0){
if(n&1){
digit[ctr]=1;
}
ctr++;
n/=2;
}
if(plus){
for(ll i=ctr-1; i>0; i--){
if(i&1){
if(digit[i]==1) digit[i+1]++;
}
}
repi(i,1,45){
while(digit[i]>1){
digit[i+1]++;
digit[i+2]++;
digit[i]-=2;
}
}
}
else{
for(ll i=ctr-1; i>=0; i--){
if(i%2==0){
if(digit[i]==1) digit[i+1]++;
}
}
repi(i,1,45){
while(digit[i]>1){
digit[i+1]++;
digit[i+2]++;
digit[i]-=2;
}
}
}
bool start=false;
for(ll i=38;i>=0;i--){
if(!start&&digit[i]==0) continue;
if(!start&&digit[i]==1){
start=true;
cout << digit[i];
continue;
}
cout << digit[i];
}
cout << endl;
return;
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
std::cout<<std::fixed<<std::setprecision(30);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[505][505];
bool chk[23333333];
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;}
int nxtPrime(int&x){
auto chk=[&](int x){
if(x<2)return false;
for(int i=2;i*i<=x;i++)
if(x%i==0)
return false;
return true;
};
do x++;while(!chk(x));
::chk[x]=true;
return x;
}
void CCC(int n){
map<int,pair<int,int>>s;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
if(s.count(a[i][j])){
cout<<s[a[i][j]].first<<" "<<s[a[i][j]].second<<" "<<i<<" "<<j<<"\n";
break;
}
s[a[i][j]]=make_pair(i,j);
}
}
void solve(int n){
int p=0;
for(int i=1,j=n-(~n&1);i<=n;i++,j--)
if(!a[i][j]&&1<=j&&j<=n)
a[i][j]=nxtPrime(p);
for(int i=n,j=n;i>=1;i--,j--)
if(!a[i][j])
a[i][j]=nxtPrime(p);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if((i+j)%2==0){
if(a[i][j])continue;
auto get=[&](int dx,int dy)->ll{
int x=i,y=j;
while(1<=x&&x<=n&&1<=y&&y<=n){
if(chk[a[x][y]])return a[x][y];
x+=dx,y+=dy;
}
return 1;
};
a[i][j]=get(+1,+1)*get(+1,-1)*get(-1,+1)*get(-1,-1);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if((i+j)%2==1){
auto upd=[&](int dx,int dy){
if(a[i+dx][j+dy])
a[i][j]=lcm(a[i][j],a[i+dx][j+dy]);
};
a[i][j]=1;
upd(+1,0);
upd(-1,0);
upd(0,+1);
upd(0,-1);
a[i][j]++;
}
}
int main(){
solve(500);
int n;cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cout<<a[i][j]<<" \n"[j==n];
return 0;
} | 0 |
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
// AOJ 0168
// KannonDou
// input n = year
// EOF = 0
int main(){
long long a[30] = {1, 2, 4}; //a[0] = 1, a[1] = 2, a[2] = 4??§?????????
//i+1????????§?????????????????°
for(int i=3 ; i<30 ; i++){
a[i] = a[i-1] + a[i-2] + a[i-3]; //a[3]???3-4,2-4,1-4????????????
//????????°1-4??§2???3?????¢??????????????????1?????????????????????
//????????????????????????????¨?????????????????????£??????????????????????????§?§£??????
}
while(1){
int n;
cin >> n;
if(n==0) return 0;
int temp = a[n-1];
temp /= 365;
temp /= 10;
cout << temp + 1 << endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <cstring>
#include <climits>
#define MAX
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
bool primearray[10000];
void erathos()
{
int i;
memset(primearray, 0, sizeof(primearray));
REP( i, 2, 10000)
{
if( primearray[i] == 0 )
{
for( int j = i*2; j < 10000; j+=i)
{
primearray[j] = 1;
}
}
}
return;
}
int main()
{
int in;
erathos();
while( cin >> in, in)
{
for( int i = in ; i > 0; i--)
{
if( primearray[i] == 0 && primearray[i-2] == 0 )
{
cout << i-2 << " " << i << endl;
break;
}
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[111];
int n;
void bs(){
bool flag = true;
int cnt = 0;
while(flag){
flag = false;
for(int j = n-1; j > 0; j--){
if(a[j] < a[j-1]){
cnt++;
swap(a[j],a[j-1]);
flag = true;
}
}
}
for(int i = 0; i < n; i++){
if(i != n-1){
cout << a[i] << " ";
}else cout << a[i];
}
cout << endl;
cout << cnt << endl;
}
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> a[i];
}
bs();
} | #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define N 1000005
queue<int> q;
char a[N],b[N];
int main()
{
int n,i,j,ans=0;
scanf("%d%s%s",&n,a+1,b+1);
if(strcmp(a+1,b+1)==0){printf("0");return 0;}
i=j=n;
while(j){
while(j&&b[j]==b[j-1])j--;
while(i&&(i>j||a[i]!=b[j]))i--;
if(i==0){printf("-1");return 0;}
while(!q.empty()&&q.front()-(int)q.size()>=j)q.pop();
if(i!=j)q.push(i);
ans=max(ans,(int)q.size()+1);
j--;
}
printf("%d",ans);
} | 0 |
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
if(a<9 && b<9){
cout<<"Yay!"<<"\n";
}
else{
cout<<":("<<"\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void)
{
int N, K, i, min;
cin >> N >> K;
min = 1;
for (i = 0; i < N; ++i)
{
if (min * 2 < min + K)
{
min *= 2;
}
else
{
min += K;
}
}
cout << min << endl;
return (0);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>
int main() {
int A, B; cin >> A >> B;
string ans = "Yay!";
if (A > 8 || B > 8) {
ans = ":(";
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{ int a,b;
cin>>a>>b;
int r=abs(a-b);
int k=0;
if(a<b)
k=2*a+2*r;
else
k=2*b+2*r;
if(k<=16)
cout<<"Yay!";
else
cout<<":(";
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
int main() {
int k, t;
cin >> k >> t;
vector<int> a(t);
rep(i,t) cin >> a[i];
sort(all(a));
int mx = a[t-1];
int e = k-mx;
if(mx-1 <= e) cout << 0 << endl;
else cout << mx-1-e << endl;
return 0;
} | #include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
priority_queue<pair<int, int>> pq;
int k,t; cin >> k >> t;
rep(i, t) {
int a; cin >> a;
pq.push(make_pair(a, i));
}
int ans = 0;
int beforeT = -1;
while(!pq.empty()) {
auto top = pq.top(); pq.pop();
if(beforeT == top.second) {
if(pq.size() == 0) {
++ans;
--top.first;
if(top.first == 0) {
break;
} else {
pq.push(top);
continue;
}
}
auto prev = pq.top(); pq.pop();
--prev.first;
beforeT = prev.second;
if(prev.first > 0) {
pq.push(prev);
}
pq.push(top);
continue;
}
beforeT = top.second;
--top.first;
if(top.first != 0) {
pq.push(top);
}
}
std::cout << ans << endl;
return 0;
}
| 1 |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;
int main(){
int N;cin >> N;
int ans=0;
for(int i=3;i<N;i++){
ans=max(ans, N/i);
}
cout << ans << endl;
}
| #include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <cstring>
#include<cmath>
using namespace std;
int main() {
int x;
cin >> x;
cout << x / 3;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
if(a == 2){cout << -1 << endl;}
else if(a == 3){cout << "aa." <<endl;
cout << "..a" <<endl;
cout << "..a" <<endl;}
else{
int c;
c = (a/4-1)*4;
for(int i = 0;i < c/2;i++){
for(int j = 0;j < c;j++){
if(j/2==i){cout << 'a';}
else if(j==c-2*i-2){cout << 'c';}
else if(j==c-2*i-1){cout << 'd';}
else{cout << '.';}
}
for(int j = 0;j < a-c;j++){
cout << '.';}
cout << endl;
for(int j = 0;j < c;j++){
if(j/2==i){cout << 'b';}
else if(j==c-2*i-2){cout << 'c';}
else if(j==c-2*i-1){cout << 'd';}
else{cout << '.';}
}
for(int j = 0;j < a-c;j++){
cout << '.';}
cout << endl;
}
int p = a-c;
if(p == 4){
for(int i = 0;i < c;i++){cout << '.';}
cout << "aabc" << endl;
for(int i = 0;i < c;i++){cout << '.';}
cout << "ddbc" << endl;
for(int i = 0;i < c;i++){cout << '.';}
cout << "bcaa" << endl;
for(int i = 0;i < c;i++){cout << '.';}
cout << "bcdd" << endl;}
else if(p == 5){
for(int i = 0;i < c;i++){cout << '.';}cout << "aabbc" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "de..c" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "de..f" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "h.ggf" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "hiijj" << endl;}
else if(p==6){
for(int i = 0;i < c;i++){cout << '.';}cout << "aabxx." << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "c.b..z" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "cdd..z" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "xx.aab" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "..zc.b" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "..zcdd" << endl;}
else{
for(int i = 0;i < c;i++){cout << '.';}cout << "aa.bb.c" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << ".d..eec" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "fdg...." << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "f.g...h" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "...iijh" << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "zxx..j." << endl;
for(int i = 0;i < c;i++){cout << '.';}cout << "z.mm.nn" << endl;}
}
} | #include<stdio.h>
#include<algorithm>
#include<vector>
#define fst first
#define snd second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
char three[3][4] = {
"xx.",
"..y",
"..y"
};
char four[4][5] = {
"aacd",
"bbcd",
"cdaa",
"cdbb"
};
char five[5][6] = {
"aabbc",
"dx..c",
"dx..b",
"a.yyb",
"accdd"
};
char six[6][7] = {
"aacd..",
"bbcd..",
"..aacd",
"..bbcd",
"cd..aa",
"cd..bb"
};
char seven[7][8] = {
"aabbcc.",
"xx.xx.a",
"..y..ya",
"..y..yb",
"xx.xx.b",
"..y..yc",
"..y..yc"
};
char ans[1000][1000 + 1];
int main() {
int n;
scanf("%d", &n);
if (n == 2) return !puts("-1");
if (n == 3) {
for(int i = 0; i < 3; i++)
puts(three[i]);
}
else {
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = '.';
for(int st = 0; st < n;) {
if (n - st == 5) {
for (int i = 0; i < 5; i++) for (int j =0; j < 5; j++) {
ans[st + i][st + j] = five[i][j];
}
st += 5;
}
else if (n - st == 6) {
for (int i = 0; i < 6; i++) for (int j = 0; j < 6; j++) {
ans[st + i][st + j] = six[i][j];
}
st += 6;
}
else if (n - st == 7) {
for (int i = 0; i < 7; i++) for (int j = 0; j < 7; j++) {
ans[st + i][st + j] = seven[i][j];
}
st += 7;
}
else {
for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) {
ans[st + i][st + j] = four[i][j];
}
st += 4;
}
}
for (int i = 0; i < n; i++)
puts(ans[i]);
}
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
ll a,b, k; cin >> a >> b >> k;
for(int i = 0; i < k; i++){
if(i %2 == 0){
a/=2; b += a;
}else{
b/=2; a += b;
}
}
cout << a << " " << b << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,h,w;
cin >>n>>h>>w;
long long kotae=(n-h+1)*(n-w+1);
cout<<kotae<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int sum = 0;
int a, b, m = 101;
for (int i = 0; i < 4; i++){
cin >> a;
m = min(a, m);
sum += a;
}
sum -= m;
cin >> a >> b;
sum += max(a, b);
cout << sum << endl;
} | #include <iostream>
using namespace std;
int main(){
int a[6];
int sum=0;
for(int i=0;i<6;i++){
cin>>a[i];
sum+=a[i];
}
int min=100;
for(int j=0;j<4;j++){
if(min>a[j])min=a[j];
}
sum=sum-min;
if(a[4]>a[5])sum=sum-a[5];
else sum=sum-a[4];
cout<<sum<<endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int i = a; i <= (n); ++i)
#define repD(i, a, n) for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 319;
const int MOD = 998244353;
ll dp[maxn][maxn][maxn];
string s;
int k, ones, zeros;
vi numo, mino;
ll solve(int a, int b, int c){
if(dp[a][b][c] != -1){
return dp[a][b][c];
}
if(a == 0){
return (b - c == numo[a]);
}
ll ans = 0;
for(int i = 0; i <= b; i++){
int nh = b - i; // i is in this column, nh in previous
if(i - numo[a] > c) break;
if(nh < mino[a-1]) continue;
int nm = max(i - numo[a], 0);
ans = (ans + solve(a-1,nh,c-nm))%MOD;
}
dp[a][b][c] = ans;
//cout << a << " " << b << " " << c << " " << dp[a][b][c] << endl;
return ans;
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
cin >> s;
cin >> k;
int n = sz(s);
for(char c: s) if(c == '1') ones++;
zeros = n - ones;
rep(i,maxn) rep(j,maxn) rep(ii,maxn) dp[i][j][ii] = -1;
numo.pb(0);
for(char c: s){
if(c == '1') numo.back()++;
else numo.pb(0);
}
mino.resize(sz(numo));
mino[0] = numo[0];
for(int i = 1; i < sz(numo); i++){
mino[i] = mino[i-1] + numo[i];
}
ll ans = 0;
k = min(k, ones);
rep(i,k+1){
ans = (ans + solve(zeros,ones,i))%MOD;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int MAX_N = 2e3 + 6, MOD = 1e9 + 7;
int n, k;
int F[MAX_N * MAX_N];
int D[MAX_N * MAX_N];
int dp[MAX_N][MAX_N];
int _sum(int a, int b) {
int c = a + b;
if (MOD <= c)
c -= MOD;
return c;
}
int _mul(int a, int b) {
int res = 1LL * a * b % MOD;
return res;
}
int _pow(int a, int b) {
if (!b)
return 1;
int res = _pow(a, b >> 1);
res = _mul(res, res);
if (b & 1)
res = _mul(res, a);
return res;
}
int choose(int a, int b) {
if (b < a || min(a, b) < 0)
return 0;
return _mul(F[b], _mul(D[a], D[b - a]));
}
void pre_process() {
F[0] = 1;
for (int i = 1; i < MAX_N * MAX_N; i++)
F[i] = _mul(F[i - 1], i);
D[0] = 1;
for (int i = 1; i < MAX_N * MAX_N; i++)
D[i] = _pow(F[i], MOD - 2);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
pre_process();
cin >> n >> k;
if (k == 1) {
cout << "1\n";
return 0;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = 1;
for (int j = 1; j <= i; j++)
dp[i][j] = _sum(_mul(dp[i][j - 1], choose(k - 2, n * k - i - (j - 1) * (k - 1) - 1)), dp[i - 1][j]);
}
cout << _mul(dp[n][n], F[n]) << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};
struct Union_Find_Tree{
vector<int> par, rank, num;
Union_Find_Tree(int N){
par.assign(N, -1);
rank.assign(N, 0);
num.assign(N, 1);
}
int root(int x){
if(par[x] < 0 || par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y){
x = root(x), y = root(y);
if(x == y) return;
elif(rank[x] < rank[y]) par[x] = y, num[y] += num[x];
else{
par[y] = x, num[x] += num[y];
if(rank[x] == rank[y]) rank[x]++;
}
}
int size(int x) {return num[root(x)];}
bool same(int x, int y){
return root(x) == root(y);
}
void clear(){
fill(par.begin(), par.end(), -1);
fill(rank.begin(), rank.end(), 0);
fill(num.begin(), num.end(), 1);
}
};
template<typename Idempotent_Semigroup>
struct Sparse_Table{
Idempotent_Semigroup ope(Idempotent_Semigroup a, Idempotent_Semigroup b){
return min(a, b);
}
const int n;
vector<vector<Idempotent_Semigroup>> st;
vector<int> lookup;
Sparse_Table(const vector<Idempotent_Semigroup> &table) : n(sz(table)){
st.resize(n);
rep(i, n) st[i].pb(table[i]);
for(int k = 0; (1<<k) < n; k++){
rep(i, n){
if(i+(1<<k) < n) st[i].pb(ope(st[i][k], st[i+(1<<k)][k]));
else st[i].pb(st[i][k]);
}
}
lookup.resize(n+1);
lookup[0] = -1;
rep2(i, 1, n) lookup[i] = lookup[i/2]+1;
}
Idempotent_Semigroup query(int l, int r){
if(l == r) return Idempotent_Semigroup(INF, -1);
int k = lookup[r-l];
return ope(st[l][k], st[r-(1<<k)][k]);
}
Idempotent_Semigroup operator [] (int i) {return st[i][0];}
};
int main(){
int N; ll D;
cin >> N >> D;
ll A[N];
rep(i, N) cin >> A[i];
vector<pli> table1, table2;
rep(i, N){
table1.pb(pli(A[i]+D*i, i));
table2.pb(pli(A[i]-D*i, i));
}
Sparse_Table<pli> st1(table1), st2(table2);
Union_Find_Tree uft(N);
vector<int> l(N), r(N);
iota(all(l), 0), iota(all(r), 1);
ll ans = 0;
while(sz(l) > 1){
int n = sz(l);
rep(i, n){
ll vl = st2.query(0, l[i]).first + st1.query(l[i], r[i]).first;
ll vr = st1.query(r[i], N).first + st2.query(l[i], r[i]).first;
if(vl < vr){
int idl = st2.query(0, l[i]).second, idr = st1.query(l[i], r[i]).second;
if(!uft.same(idl, idr)){
ans += A[idl]+A[idr]+D*(idr-idl);
uft.unite(idl, idr);
}
}
else{
int idl = st2.query(l[i], r[i]).second ,idr = st1.query(r[i], N).second;
if(!uft.same(idl, idr)){
ans += A[idl]+A[idr]+D*(idr-idl);
uft.unite(idl, idr);
}
}
}
l.clear(), r.clear();
int now = 0;
while(now < N){
l.pb(now), r.pb(now += uft.size(now));
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
int a[200010],d,n,ans;
int dpl[200010],dpr[200010];
signed main(){
cin>>n>>d;
for(int i=1 ;i<=n;i++)cin>>a[i],ans+=a[i];
ans+=(n-1)*d;
dpr[1]=a[1];
for(int i=2;i<=n;i++)dpr[i]=min(a[i],dpr[i-1]+d);
dpl[n]=a[n];
for(int i=n-1;i>=1;i--)dpl[i]=min(a[i],dpl[i+1]+d);
for(int i=2;i<n;i++)ans+=min(dpl[i],dpr[i]);
cout<<ans<<endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
// ここから編集
void solve(){
int N;cin >> N;
vector<ll>a(N);
REP(i,N)cin >> a[i];
string s; cin >> s;
vector<ll> b;
for(int i=N-1; i>=0; i--){
ll v = a[i];
for(auto x:b) chmin(v, v^x);
if(v){
if(s[i] == '1'){
cout << 1 << endl;
return;
}
b.push_back(v);
}
}
cout << 0 << endl;
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int ans = 0;
for (int i = 1; i < N; i++) {
int d = A[i - 1] - A[i];
if (d > 0) {
ans += d;
A[i] = A[i - 1];
}
}
cout << ans << endl;
return 0;
} | 0 |
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <memory>
#include <iomanip>
std::vector<int> parse_line(std::string const& line) {
using namespace std;
vector<int> result;
istringstream s(line);
string element;
while (getline(s, element, ' ')) {
stringstream buf;
int value = 0;
buf << element;
buf >> value;
result.push_back(value);
}
return std::move(result);
}
int main(int argc, char* argv[])
{
using namespace std;
while (true) {
string line;
getline(std::cin, line);
auto elements = parse_line(line);
auto length = elements[0];
if (length == 0) break;
vector<int> total(length + 1);
size_t width = length + 1;
for (size_t i = 0; i < length; ++i) {
getline(cin, line);
elements = parse_line(line);
int sum = 0;
for (size_t n = 0; n < length; ++n) {
int val = elements[n];
sum += val;
total[n] += val;
cout << setw(5) << val;
}
cout << setw(5) << sum << endl;
total[length] += sum;
}
for (size_t i = 0; i < width; ++i) {
cout << setw(5) << total[i];
}
cout << endl;
}
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
int a[11][11];
int main()
{
int i, j;
int n;
while (1){
cin >> n;
if (n == 0){
break;
}
for (i = 0; i <= n; i++){
for (j = 0; j <= n; j++){
a[i][j] = 0;
}
}
for (i = 0; i < n; i++){
for (j = 0; j < n; j++){
cin >> a[i][j];
}
}
for (i = 0; i < n; i++){
for (j = 0; j <= n; j++){
a[i][n] += a[i][j];
}
}
for (j = 0; j <= n; j++){
for (i = 0; i <= n; i++){
a[n][j] += a[i][j];
}
}
for (i = 0; i <= n; i++){
a[i][n] /= 2;
}
for (j = 0; j <= n; j++){
a[n][j] /= 2;
}
for (i = 0; i <= n; i++){
printf("%5d", a[i][0]);
for (j = 1; j <= n; j++){
printf("%5d", a[i][j]);
}
cout << endl;
}
}
return 0;
} | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> p, r;
void makeSet(int x){
p[x] = x;
r[x] = 0;
}
int findSet(int x){
if(x != p[x])p[x] = findSet(p[x]);
return p[x];
}
void link(int x, int y){
if(r[x] > r[y]) p[y] = x;
else {
p[x] = y;
if(r[x] == r[y]) r[y] = r[y] + 1;
}
}
void unite(int x, int y){
link(findSet(x), findSet(y));
}
struct Edge{
int a, b, 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());
int min_cost = 0;
for(int i=0; i<es.size(); i++){
Edge& e = es[i];
if(!(findSet(e.a)==findSet(e.b))){
min_cost += e.cost;
unite(e.a, e.b);
}
}
return min_cost;
}
};
Edge e;
int main(){
int V, E, i;
Graph g;
cin >> V >> E;
p.resize(V);
r.resize(V);
for(i=0; i<V; i++) makeSet(i);
for(i=0; i<E; i++){
cin >> e.a >> e.b >>e.cost;
g.es.push_back(e);
}
cout << g.kruskal() << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
vector<int>E[200000];
int id[200000];
int col[200000];
bool b[200000];
bool dfs(int v,int k,int c){
id[v]=k;
col[v]=c;
bool flag=true;
for(int u:E[v]){
if(id[u]==-1){
flag&=dfs(u,k,!c);
}
else{
if(col[u]==col[v])flag=false;
}
}
return flag;
}
vector<int>v[200000];
int main(){
int n,m;cin>>n>>m;
rep(i,m){
int a,b;scanf("%d%d",&a,&b);a--;b--;
E[a].push_back(b);
E[b].push_back(a);
}
memset(id,-1,sizeof(id));
int cnt=0;
rep(i,n){
if(id[i]==-1){
b[cnt]=dfs(i,cnt,0);
cnt++;
}
v[id[i]].push_back(i);
}
ll c1=0,c2=0,c3=0;
rep(i,cnt){
if(v[i].size()==1){
c1++;
continue;
}
c2++;
if(b[i])c3++;
}
cout<<c1*(n-c1)*2+c1*c1+c2*c2+c3*c3<<endl;
} | 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;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pair;
vector<Pair> rects;
bool Compare(const Pair &a, const Pair &b) {
int h1 = a.first;
int h2 = b.first;
int w1 = a.second;
int w2 = b.second;
int t1 = h1*h1+w1*w1;
int t2 = h2*h2+w2*w2;
if (t1 != t2) return t1 < t2;
return h1 < h2;
}
int main() {
for (int i=1; i<200; i++) {
for (int j=i+1; j<200; j++) {
rects.push_back(Pair(i, j));
}
}
sort(rects.begin(), rects.end(), Compare);
while (1) {
int h, w;
scanf("%d%d", &h, &w);
if (h == 0 && w == 0) return 0;
Pair ans = *upper_bound(rects.begin(), rects.end(), Pair(h, w), Compare);
printf("%d %d\n", ans.first, ans.second);
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c,k,sum=0;
cin >> a >> b >> c >> k;
sum+=(a+b+c);
long long x=max(a,max(b,c));
sum-=x;
for(long long i=0; i<k; i++){
x*=2;
}
cout << x+sum << endl;
} | #include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int s[5];
int ans=-1;
string x;
int flg=0;
void wf(int i,int w ,int z) //i文字目までの部分和w zで+と-の状況を管理
{
if(flg==1){return;}
int g,h;
//+を挿入した場合の処理
g=w+s[i]; h=z*10+1; if(i!=4){wf(i+1,g,h);} if(i==4&&g==7){ans=h; flg=1; return;}
//-を挿入した場合の処理
g=w-s[i]; h=z*10; if(i!=4){wf(i+1,g,h);} if(i==4&&g==7){ans=h;flg=1; return;}
}
int main()
{
cin>>x;
for(int i=1;i<=4;i++)
{
s[i]=x[i-1]-'0';
}
wf(2,s[1],0);
//ansを解読する作業
int dx=100;
for(int i=1;i<4;i++)
{
printf("%d",s[i]);
if(ans>=dx){printf("+");ans=ans-dx;}
else {printf("-");}
dx=dx/10;
}
printf("%d=7",s[4]);
} | 0 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
vector<int> W, K;
int dommy;
for (int i = 0; i < 10; ++i) {
cin >> dommy;
W.push_back(dommy);
}
sort(W.begin(), W.end(), greater<int>());
for (int i = 0; i < 10; ++i) {
cin >> dommy;
K.push_back(dommy);
}
sort(K.begin(), K.end(), greater<int>());
int Wpoint = 0, Kpoint = 0;
for (int i = 0; i < 3; ++i) {
Wpoint += W[i];
}
for (int i = 0; i < 3; ++i) {
Kpoint += K[i];
}
cout << Wpoint << ' ' << Kpoint << endl;
return 0;
} | //32
#include<iostream>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
int main(){
int p[2][10];
for(int i=0;i<2;i++){
for(int j=0;j<10;j++){
cin>>p[i][j];
}
}
for(int i=0;i<2;i++){
sort(p[i],p[i+1],greater<int>());
cout<<accumulate(p[i],p[i]+3,0)<<((i==0)?' ':'\n');
}
return 0;
} | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.