code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000010;
int cnt=0,G[100];
void Insertion_Sort(int s,int t,int n,int* A)
{
for(int i=s+t;i<n;i+=t)
{
int key=A[i],j=i-t;
while(j>=0&&A[j]>key)
{
A[j+t]=A[j];
j-=t;
cnt++;
}
if(A[j+t]!=key)
{
A[j+t]=key;
//cnt++;
}
}
}
int main()
{
for(int i=0;(G[i]=G[i-1]*3+1)<=MAXN;i++);
static int n,A[MAXN];
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&A[i]);
int t;
for(t=0;G[t]<=n;t++);
printf("%d\n",t);
for(int i=t-1;i>=0;i--)
printf("%d%c",G[i],i==0?'\n':' ');
for(int i=t-1;i>=0;i--)
for(int j=0;j<G[i];j++)
Insertion_Sort(j,G[i],n,A);
printf("%d\n",cnt);
for(int i=0;i<n;i++)
printf("%d\n",A[i]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
int main() {
int N;
cin>>N;
string s,t;
cin>>s>>t;
reverse(s.begin(),s.end());
for(int i=N;i<=2*N;i++){
string S=s.substr(0,2*N-i);
reverse(S.begin(),S.end());
if(S==t.substr(0,2*N-i)){cout<<i<<endl;return 0;}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL<<32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
#define Endl endl
/*--------------------template--------------------*/
static const int MAX = 100;
ll d[MAX][MAX];
void floyd()
{
REP(k, n)
{
REP(i, n)
{
if (d[i][k] == INF)
{
continue;
}
REP(j, n)
{
if (d[k][j] == INF)
{
continue;
}
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
int main()
{
ll e, u, v, c;
cin >> n >> e;
REP(i, n)
{
REP(j, n)
{
d[i][j] = ((i == j) ? 0 : INF);
}
}
REP(i, e)
{
cin >> u >> v >> c;
d[u][v] = c;
}
floyd();
bool negative = false;
REP(i, n)
{
if (d[i][i] < 0)
{
negative = true;
}
}
if (negative)
{
cout << "NEGATIVE CYCLE" << endl;
}
else
{
REP(i, n)
{
REP(j, n)
{
if (j)
{
cout << " ";
}
if (d[i][j] == INF)
{
cout << "INF";
}
else
{
cout << d[i][j];
}
}
cout << endl;
}
}
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int nax = 5010;
const ll INF = 1e18L;
ll dp[nax][nax];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
for (int i = 0; i < nax; ++i) {
for (int j = 0; j <= i; ++j) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
int n;
cin >> n;
vector<pair<int, int>> q(n);
for (int i = 0; i < n; ++i) {
cin >> q[i].first >> q[i].second;
q[i].first += q[i].second;
}
sort(q.begin(), q.end());
for (int i = 0; i < n; ++i) {
q[i].first -= q[i].second;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= i; ++j) {
if (dp[i][j] == INF) continue;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (dp[i][j] <= q[i].first) {
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + q[i].second);
}
}
}
int ans = 0;
for (int i = 0; i <= n; ++i) {
if (dp[n][i] != INF) {
ans = i;
}
}
cout << ans << '\n';
} | 0 |
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>>
#define fi first
#define se second
void print(Vl vec){
rep(i, 0, sz(vec)){
if(i) cout << " ";
cout << vec[i];
}
coel;
}
////////////////////////////////////////////////////////
ll RepeatSquaring(ll N, ll P, ll M){
if(P==0) return 1;
if(P%2==0){
ll t = RepeatSquaring(N, P/2, M);
return t*t % M;
}
return N * RepeatSquaring(N, P-1, M);
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
const ll mod = 998244353;
int main() {
ll n; cin >> n;
Vl d(n);
rep(i, 0, n) cin >> d[i];
if(d[0] != 0){
cout << 0 << endl;
return 0;
}
map<ll, ll> cnt;
rep(i, 0, n) cnt[d[i]]++;
ll si = sz(cnt);
rep(i, 0, si) if(cnt[i] == 0) {co(0); return 0;}
if(cnt[0] != 1) {co(0); return 0;}
if(d[0] != 0) {co(0); return 0;}
ll ans = 1;
rep(i, 0, si){
// ans *= RepeatSquaring(cnt[i], cnt[i+1], mod);
ans *= modpow(cnt[i], cnt[i+1], mod);
ans %= mod;
}
co(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
ll Ep(int x, int y){
if(y == 1) return x;
ll r = Ep(x,y/2);
if(y%2 == 1) return r *r%MOD *x%MOD;
else return r *r%MOD;
}
int main(){
int n, x;
cin >> n;
cin >> x;
if(x != 0){
cout << 0 << endl;
return 0;
}
map<int, int> mp;
for(int i=1; i<n; ++i){
cin >> x;
if(x == 0){
cout << 0 << endl;
return 0;
}
++mp[x];
}
ll ans = 1;
for(auto p: mp){
if(p.first == 1) continue;
ans *= Ep(mp[p.first-1], p.second);
ans %= MOD;
}
cout << ans << endl;
} | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<pair<int,int>> v;
for(int i = 1; i <= n; i++){
int x, y;
cin >> x >> y;
v.push_back({x, y});
}
int result = 0;
for(int i = 1; i < v.size(); i++)
if(v[i].second < v[0].second)
swap(v[0], v[i]);
sort(v.begin() + 1, v.end());
for(int i = 0; i < v.size(); i++)
result = max(result, v[i].second - v[i].first + 1);
for(int i = 1;i < v.size() - 1; i++)
result = max(result, (v[i].second - v[i].first + 1) + (v[0].second - max(v[0].first, v.back().first) + 1));
int minr = v.back().second;
for(int i = v.size() - 1; 1 <= i; i--){
minr = min(minr, v[i].second);
result = max(result, (minr - v.back().first + 1) + (v[0].second - max(v[0].first, v[i - 1].first) + 1));
}
cout << result;
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
using namespace std;
int main() {
int i, j, k, to, min, temp_result;
int n;
int r[100], c[100];
int result[100][100];
cin >> n;
for (i = 0; i < n; i++) {
cin >> r[i] >> c[i];
result[i][i] = 0;
}
i = 0;
j = 1;
to = n - 2;
while (j <= n - 1) {
while (i <= to) {
//computation of result[i][i+j]
min = INT_MAX;
k = i;
while (k <= i + j - 1) {
temp_result = c[k] * r[i] * c[i + j] + result[i][k] + result[k + 1][i + j];
if (temp_result < min) {
min = temp_result;
}
k++;
}
result[i][i + j] = min;
i++;
}
i = 0;
j++;
to--;
}
printf("%d\n", result[0][n - 1]);
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int ans = 753;
for(int i = 0; i <= S.size()-3; ++i){
int buf = (S[i]-'0')*100 + (S[i+1]-'0')*10 + (S[i+2]-'0');
ans = min(ans, abs(buf-753));
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cout<<n + (n*n) + (n*n*n);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "C"
int n;
ll x;
ll start;
class subject{
public:
ll b, l, u, w;
void input(){
read(b);
read(l);
read(u);
start+=b*l;
w=(x-b)*u+b*l;
}
ll cost(ll x){
if(x<=b*l){
return (x-1)/l+1;
}
else{
x-=b*l;
return b+(x-1)/u+1;
}
}
} s[100001];
ll f[100001];
int get(int i){
int res=n;
int low=0, high=n-1, mid;
while(low<=high){
mid=(low+high)/2;
ll sum=f[mid];
if(mid<i) sum+=s[i].w;
if(sum>=start){
res=mid;
high=mid-1;
}
else low=mid+1;
}
return res;
}
int main(){
#ifdef Aria
if(fopen(taskname".in", "r"))
freopen(taskname".in", "r", stdin);
#endif // Aria
read(n);
read(x);
FOR(i, 1, n) s[i].input();
sort(s+1, s+n+1, [](subject A, subject B){
return A.w>B.w;
});
ll ans=x*n;
FOR(i, 1, n) f[i]=f[i-1]+s[i].w;
FOR(i, 1, n){
int j=get(i);
ll res=x*j;
if(j>i) res-=x;
ll now=start-f[j];
if(j>i) now+=s[i].w;
if(now>0) ans=min(ans, res+s[i].cost(now));
else ans=min(ans, res);
}
writeln(ans);
} | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stdint.h>
namespace asl
{
template <typename T>
using vec = std::vector<T>;
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec)
{
for (auto &value : vec)
is >> value;
return is;
}
template <typename T>
struct fenwick
{
int n;
std::vector<T> f;
fenwick(int n) : n(n), f(n + 1) {}
T query(int p)
{
T ret = 0;
for (++p; p > 0; p -= p & -p)
ret += f[p];
return ret;
}
void update(int p, T x)
{
for (++p; p <= n; p += p & -p)
f[p] += x;
}
};
template <typename T>
using BIT = fenwick<T>;
}
#include <experimental/optional>
#include <tuple>
namespace asl
{
typedef long long i64;
}
#include <random>
#include <utility>
#define endl '\n'
using namespace std;
using namespace asl;
void solve()
{
int n, q;
cin >> n >> q;
vec<int> val(n);
cin >> val;
BIT<i64> bit(n);
for (int i = 0; i < n; ++i)
bit.update(i, val[i]);
while (q--)
{
int t;
cin >> t;
if (t == 0)
{
int p, x;
cin >> p >> x;
bit.update(p, x);
}
else
{
int l, r;
cin >> l >> r;
cout << bit.query(r - 1) - bit.query(l - 1) << endl;
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
for (int i = 1; i <= t; ++i)
{
solve();
}
return 0;
}
| 0 |
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll maxn=1e5+10;
ll mm,m,n,a[60];
ll f[60];
ll ans;
inline void read(ll &x)
{
ll f;char c;
for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
void dfs(ll x,ll n,ll sum){
if(x==n/2+1){
if(sum==m){
ll now=a[1]>=0?(9-a[1]):(9+a[1]);
for(register ll i=2;i<x;i++)
now*=(a[i]>=0?(10-a[i]):(10+a[i]));
ans+=n&1?now*10:now;
}
return ;
}
if(sum+10ll*(f[n-x]-f[x-1])<m||sum-10ll*(f[n-x]-f[x-1])>m)
return ;
for(register ll i=-9;i<10;i++){
a[x]=i;
dfs(x+1,n,sum+1ll*a[x]*(f[n-x]-f[x-1]));
}
}
int main(){
read(m);
mm=m;f[0]=1;
while(mm) n++,mm/=10;
for(register ll i=1;i<=18;i++) f[i]=f[i-1]*10;
for(register ll i=n;i<=18;i++) dfs(1,i,0);
printf("%lld\n",ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
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;}
template<typename F>
struct FixPoint : F{
FixPoint(F&& f):F(forward<F>(f)){}
template<typename... Args>
decltype(auto) operator()(Args&&... args) const{
return F::operator()(*this,forward<Args>(args)...);
}
};
template<typename F>
inline decltype(auto) MFP(F&& f){
return FixPoint<F>{forward<F>(f)};
}
__int128_t abs128(__int128_t val){return val<0?-val:val;}
ostream &operator<<(ostream &os,__int128_t val){
if(ostream::sentry(os)){
__uint128_t tmp=abs128(val);
char buf[64];
char *d=end(buf);
do{
--d;
*d=char(tmp%10+'0');
tmp/=10;
}while(tmp);
if(val<0) *--d='-';
int len=end(buf)-d;
if(os.rdbuf()->sputn(d,len)!=len){
os.setstate(ios_base::badbit);
}
}
return os;
}
istream &operator>>(istream &is,__int128_t &val){
string s;
is>>s;
val=0;
for(int i=0;i<(int)s.size();i++)
if(isdigit(s[i])) val=val*10+s[i]-'0';
if(s[0]=='-') val*=-1;
return is;
}
//INSERT ABOVE HERE
signed main(){
using ll = __int128_t;
ll d;
cin>>d;
const ll MAX = 37;
ll ans=0;
vector<ll> po(MAX,1);
for(int i=0;i+1<MAX;i++)
po[i+1]=po[i]*10;
vector<ll> c1(12,0),c2(12,0);
for(int i=1;i<10;i++)
for(int j=1;j<=i;j++)
c1[abs(i-j)]++;
for(int i=0;i<10;i++)
for(int j=0;j<=i;j++)
c2[abs(i-j)]++;
for(int l=2;l<=MAX;l++){
// [s, t]
ans+=
MFP([&](auto dfs,ll s,ll t,ll w)->ll{
if(s>=t){
if(w!=0) return 0;
return s==t?10:1;
}
ll dif=po[t]-po[s];
ll x=w/dif;
if(x>=10) return 0;
ll res=0;
res+=(s==0?c1:c2)[x+0]*dfs(s+1,t-1,abs128(w-(x+0)*dif));
res+=(s==0?c1:c2)[x+1]*dfs(s+1,t-1,abs128(w-(x+1)*dif));
return res;
})(0,l-1,d);
}
cout<<ans<<endl;
return 0;
}
| 1 |
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=1e5+2;
pair<int,pair<int,int> > ar[N];
pair<int,int> wow[N];
int sum[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,x,i,j,k,l=0,val,val1,max1;
int lef=0,rig=0,mid;
cin>>n>>x;
for(i=1;i<=n;i++){
cin>>ar[i].first>>ar[i].second.first>>ar[i].second.second;
rig+=ar[i].first;
l+=-ar[i].first*ar[i].second.first;
wow[i].first=ar[i].first*(ar[i].second.first-ar[i].second.second)+x*ar[i].second.second;
wow[i].second=i;
}
sort(wow+1,wow+1+n,[&](pair<int,int> cac,pair<int,int> cac1){
return cac.first>cac1.first;
});
for(i=1;i<=n;i++){
sum[i]=sum[i-1]+wow[i].first;
}
while(rig>lef){
mid=(lef+rig)/2;
val=mid/x;
val1=mid%x;
max1=sum[val];
for(i=1;i<=n;i++){
j=wow[i].second;
if(i<=val){
if(val1>ar[j].first){
max1=max(max1,sum[val+1]-wow[i].first+ar[j].first*(ar[j].second.first-ar[j].second.second)+val1*ar[j].second.second);
}
else{
max1=max(max1,sum[val+1]-wow[i].first+val1*ar[j].second.first);
}
}
else{
if(val1>ar[j].first){
max1=max(max1,sum[val]+ar[j].first*(ar[j].second.first-ar[j].second.second)+val1*ar[j].second.second);
}
else{
max1=max(max1,sum[val]+val1*ar[j].second.first);
}
}
}
if(max1+l>=0){
rig=mid;
}
else{
lef=mid+1;
}
}
cout<<rig;
} | #include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define MREP(i,x) for(int i=beg[x],v;v=to[i],i;i=las[i])
#define debug(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define y1 asdasd
typedef long long ll;
using namespace std;
void File(){
freopen("speech.in","r",stdin);
freopen("speech.out","w",stdout);
}
template<typename T>void read(T &_){
T __=0,mul=1; char ch=getchar();
while(!isdigit(ch)){
if(ch=='-')mul=-1;
ch=getchar();
}
while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
_=__*mul;
}
const int maxn=2000+10;
int n,m,a[maxn][maxn],b[maxn][maxn],ans;
char s[maxn];
stack<int>stk;
int main(){
//File();
read(n); read(m);
if(n==1 || m==1)return printf("%d\n",n*m),0;
REP(i,1,n){
scanf("%s",s+1);
REP(j,1,m)a[i][j]=(s[j]=='#');
}
REP(i,1,n-1)REP(j,1,m-1){
int c[2]={0};
++c[a[i][j]];
++c[a[i+1][j]];
++c[a[i][j+1]];
++c[a[i+1][j+1]];
b[i][j]=!(c[1]%2);
if(b[i][j])b[i][j]+=b[i-1][j];
}
/*REP(i,1,n-1){
REP(j,1,n-1)
cout<<b[i][j]<<" ";
cout<<endl;
}*/
REP(i,1,n-1){
int las;
REP(j,1,m-1){
las=j;
while(!stk.empty() && b[i][stk.top()]>=b[i][j]){
las=stk.top(); stk.pop();
if(b[i][las])ans=max(ans,(j-las+1)*(b[i][las]+1));
}
b[i][las]=b[i][j];
stk.push(las);
}
while(!stk.empty()){
las=stk.top(); stk.pop();
if(b[i][las])ans=max(ans,(m-las+1)*(b[i][las]+1));
}
}
printf("%d\n",max(ans,max(n,m)));
return 0;
} | 0 |
#include <iostream>
using namespace std;
int solve(int x){
if(x == 1) return 3;
else if(x == 2) return 2;
else if(x == 3) return 1;
else return 0;
}
int main() {
// your code goes here
int x, y; cin>>x>>y;
int answer = solve(x);
answer += solve(y);
if(x == y && x == 1) answer += 4;
cout<<answer * 100000;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
double a; /* 現在のレーティング */
double b; /* 目標のレーティング */
//
// ( a + x ) / 2 = b
// x = 2b -a
//
cin >> a;
cin >> b;
cout << (2.0 * b) - a << endl;
} | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
ll N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
ll ans = 5;
ll mincap = min(min(min(A, B), min(C, D)), E);
ans += N / mincap - 1;
if (N % mincap != 0) ++ans;
cout << ans << endl;
}
| // Copyright © 2019 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 305
#define MOD 998244353
using namespace std;
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
typedef long long i64;
i64 N, sum;
i64 a[MAX];
i64 memo[MAX][90005];
i64 dp( i64 x , i64 s )
{
if( x > N )
{
if( s >= ( sum + 1 ) / 2 )
return 1;
return 0;
}
if( memo[x][s] != -1 )
return memo[x][s];
i64 ans = 0;
ans += 2 * dp( x + 1 , s );
ans += dp( x + 1 , s + a[x] );
ans %= MOD;
return memo[x][s] = ans;
}
i64 dp2( i64 x , i64 s )
{
if( x > N )
{
if( s == sum / 2 )
return 1;
return 0;
}
if( memo[x][s] != -1 )
return memo[x][s];
i64 ans = dp2( x + 1 , s ) + dp2( x + 1 , s + a[x] );
ans %= MOD;
return memo[x][s] = ans;
}
int main()
{
optimiza_io
memset( memo , -1 , sizeof memo );
cin >> N;
i64 ansi = 1;
for( i64 i = 1; i <= N; i ++ )
{
cin >> a[i];
sum += a[i];
ansi *= 3;
ansi %= MOD;
}
i64 tmp = 3 * dp( 1 , 0 );
if( sum % 2 == 0 )
{
memset( memo , -1 , sizeof memo );
tmp -= 3 * dp2( 1 , 0 );
tmp %= MOD;
tmp += MOD;
tmp %= MOD;
}
cout << ( ( ( ansi - tmp ) % MOD ) + MOD ) % MOD << "\n";
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
//
int num;
string str;
long long cnt = 0;
long long all = 0;
cin >> num >> str;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < num; i++) {
if (str.at(i) == 'R')
r.push_back(i);
else if (str.at(i) == 'G')
g.push_back(i);
else if (str.at(i) == 'B')
b.push_back(i);
}
all = r.size() * g.size() * b.size();
for (int i = 0; i < num; i++) {
for (int j = i+1; j < num; j++) {
long long k = j * 2 - i;
if (k >= num || str.at(i) == str.at(j)) continue;
if (str.at(k) == str.at(i) || str.at(k) == str.at(j)) continue;
all--;
/*
for (int k = 0; k < b.size(); k++) {
if (g.at(j) - r.at(i) == b.at(k) - g.at(j)) continue;
if (b.at(k) - g.at(j) == r.at(i) - b.at(k)) continue;
if (r.at(i) - b.at(k) == g.at(j) - r.at(i)) continue;
cnt++;
}
*/
}
}
cout << all;
//
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> r,g,b;
for(int i = 0; i < n; i++) {
char x;
cin >> x;
if(x=='R') r.push_back(i+1);
if(x=='G') g.push_back(i+1);
if(x=='B') b.push_back(i+1);
}
ll ans = r.size()*g.size()*b.size();
if(ans==0){
cout << 0 << endl;
return 0;
}
for(int i = 0; i < r.size(); i++) {
for(int j = 0; j < g.size(); j++) {
int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin();
if(y!=b.size()){
if(b[y]==g[j]+g[j]-r[i]) ans--;
}
y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin();
if(y!=b.size()){
if(b[y]==r[i]+r[i]-g[j]) ans--;
}
if((r[i]+g[j])%2==0){
y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin();
if(y!=b.size()){
if(b[y]==(r[i]+g[j])/2) ans--;
}
}
}
}
cout << ans << endl;
return 0;
} | 1 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>
using namespace std;
#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "
const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;
const int mxn = 200000;
vii a;
vi p;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
a.assign(n, vi(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
p.assign((1 << n), 0);
for (int j = 0; j < (1 << n); ++j) {
for (int i = 0; i < n; ++i) {
if (!(j & (1 << i))) continue;
for (int k = i + 1; k < n; ++k) {
if (!(j & (1 << k))) continue;
p[j] += a[i][k];
}
}
}
vi dp(1 << n, 0);
for (int i = 0; i < n; ++i) {
for (int j = (1 << i); j <= (1 << (i + 1)) - 1; ++j) {
for (int k = j; k; k = (k - 1) & j) {
dp[j] = max(dp[j], p[k] + dp[j - k]);
}
}
}
cout << dp[(1 << n) - 1];
} | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll dp[1<<16], score[1<<16];
ll a[16][16];
ll rec(int S){
if(dp[S] != -1) return dp[S];
if(S == 0) return dp[S] = 0;
ll ret = score[S];
for(int T=S; T>0; T=T-1&S){
if(S==T) continue;
chmax(ret, rec(T) + rec(S^T));
}
return dp[S] = ret;
}
int main(void){
int N; cin >> N; REP(i,1<<N) dp[i] = -1;
REP(i,N)REP(j,N) cin >> a[i][j];
REP(S,1<<N){
REP(i,N)FOR(j,i+1,N) if(S>>i & S>>j & 1) score[S] += a[i][j];
}
ll ans = rec((1<<N)-1);
cout << ans << en;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll N;
cin >> N;
ll A = 0;
REP(i,0,N) {
ll a;
cin >> a;
A |= a;
}
ll cnt = 0;
while((A & 1) == 0) {
A >>= 1;
++cnt;
}
PR(cnt);
return 0;
}
/*
*/ | #include <bits/stdc++.h>
# define M_PI 3.14159265358979323846 /* pi */
using namespace std;
int main() {
int N;
cin >> N;
vector<int>A(N);
int count = 0;
int result = 200;
for (int i = 0; i < N; i++) {
cin >> A.at(i);
while (true) {
if (A.at(i) % 2 != 0 || A.at(i) == 0) {
break;
}
else if (A.at(i) % 2 == 0) {
A.at(i) = A.at(i) / 2;
count++;
}
}
result = min(result, count);
count = 0;
}
cout << result << endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,l;
cin >> n >> l;
if(l>=0)cout << (2*l+n-1)*n/2-l << endl;
else if(n+l>0){
cout << (2*l+n-1)*n/2 << endl;
}
else {
cout << (2*l+n-1)*n/2-(l+n-1) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n, l;
cin >> n >> l;
int ans = 0;
for(int i=l; i<l+n; ++i){
if(l+n-1 < 0 && i == l+n-1) continue;
if(l > 0 && i == l) continue;
ans += i;
}
cout << ans << endl;
} | 1 |
#include<stdio.h>
#include<math.h>
int main(){
double x1, x2;
double y1, y2;
double L, l;
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
L = pow(x2-x1, 2.0) + pow(y2-y1, 2.0);
l = sqrt(L);
printf("%f", l);
return 0;
} | #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
int main() {
double x1, y1, x2, y2, num, ans = 0, dou = 1, xx;
cin >> x1 >> y1 >> x2 >> y2;
num = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
while (dou < num) {
dou *= 10;
}
xx = dou;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < i; j++) {
dou *= 0.1;
}
if (dou < 0.000001)break;
for (int j = 0; j < 10; j++) {
ans += dou;
//cout << ans << " " << j << " " << dou << endl;
if (ans*ans > num) {
ans -= dou;
break;
}
}
dou = xx;
}
printf("%f\n", ans);
//cout << ans;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
if (!target.empty()) {
std::string::size_type pos = 0;
while ((pos = s.find(target, pos)) != std::string::npos) {
s.replace(pos, target.length(), replacement);
pos += replacement.length();
}
}
return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
bool DEBUG = 0;
template<class T> void dprint(T s){
if(DEBUG){ cout << s << "\n"; }
}
int main(int argc,char* argv[]){
if(argc>1 && argv[1][0]=='D'){ DEBUG=1;}
dprint("start");
ll N; cin>>N;
ll a[N]; CINA(a,N); reverse(a,a+N);
vector<ll> v;
v.push_back(a[0]);
for(int i=1;i<N;++i){
int m = v.size();
if(a[i]>=v[m-1]){
v.push_back(a[i]);
}else{
auto x = upper_bound(ALL(v),a[i]);
while(*x==a[i]){
++x;
}
*x = a[i];
}
}
if(DEBUG){ for(auto x:v){ cout << x << " ";} cout << "\n"; }
cout << v.size() << "\n";
} | #include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
int main () {
int n, q ;
string s ;
cin >> n >> q ;
cin >> s ;
vector<int> l (q), r(q) ;
rep(i, q){
cin >> l[i] >> r[i] ;
l[i]-- ;
r[i]-- ;
}
vector<int> num (n) ;
rep(i, n - 1){
if(s[i] == 'A' && s[i + 1] == 'C'){
num[i + 1]++ ;
}
}
for(int i = 1 ; i < n ; i++){
num[i] += num[i - 1] ;
}
vector<int> ans ;
rep(i, q){
ans.push_back(num[r[i]] - num[l[i]]) ;
}
rep(i, q){
cout << ans[i] << endl ;
}
}
| 0 |
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;
int main(){
int h,w;
cin>>h>>w;
vector<string> s(h);
for(int i=0;i<h;i++) cin>>s[i];
int res = max(h,w);
vector<vector<int>> b(h-1,vector<int>(w-1));
auto judge=[&](int i,int j){
return (int)(s[i][j]=='#');
};
for(int i=0;i+1<h;i++){
for(int j=0;j+1<w;j++){
int cnt = judge(i,j) + judge(i+1,j) +judge(i,j+1) + judge(i+1,j+1);
b[i][j] = (cnt%2==0);
}
}
vector<vector<int>> sum(h,vector<int>(w));
for(int i=0;i<h-1;i++){
for(int j=0;j<w-1;j++){
if(b[i][j]) sum[i+1][j] = sum[i][j]+1;
}
}
for(int i=0;i<h-1;i++){
int x = i+1;
stack<pair<int,int>> lh;
lh.push({-1,0});
for(int y=0;y<w;y++){
while(sum[x][y]<lh.top().second){
auto tmp = lh.top(); lh.pop();
int height = tmp.second;
int width = y-lh.top().first;
res = max(res,width*(height+1));
}
lh.push({y,sum[x][y]});
}
}
cout<<res<<endl;
return 0;
}
| #include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;
//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;
const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}
struct oreno_initializer {
oreno_initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} oreno_initializer;
// 2*2の正方形のうち黒の個数と白の個数がどちらも偶数のものは全部黒にできる
// どちらも奇数のものはできない(白黒反転は可)
// そういう正方形を内側に含まないような最大の長方形を求める
int h, w, ng[2020][2020], x[2020], res;
string s[2020];
signed main() {
cin >> h >> w;
res = max(h,w);
rep(i,h) cin >> s[i];
rep(i,h) {
rep(j,w-1) {
if (i && !(s[i-1][j]^s[i-1][j+1]^s[i][j]^s[i][j+1])) x[j]++;
else x[j] = 1;
}
stack<int> s;
rep(r,w) {
while (!s.empty() && x[s.top()]>=x[r]) {
int t = s.top(); s.pop();
int l = (s.empty() ? -1 : s.top());
chmax(res, x[t]*(r-l));
}
s.push(r);
}
}
cout << res << endl;
} | 1 |
//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 = 607;
int n;
struct G {
int d, c[N][N];
vector<pi> p;
inline bool pd(int x, int y) {
return x >= 0 && x < n * 2 && y >= 0 && y < n * 2 && !~c[x][y];
}
void dfs(int x, int y, int z) {
c[x][y] = z;
for (pi o : p) {
int X = x + o.fi, Y = y + o.se;
if (pd(X, Y)) dfs(X, Y, z ^ 1);
}
}
inline void main() {
rd(d);
for (int i = 0; i < n * 2; i++)
for (int j = 0; j < n * 2; j++)
c[i][j] = -1;
for (int i = 1 - n * 2; i < n * 2; i++)
for (int j = 1 - n * 2; j < n * 2; j++)
if (i * i + j * j == d) p.pb(mp(i, j));
for (int i = 0; i < n * 2; i++)
for (int j = 0; j < n * 2; j++)
if (pd(i, j)) dfs(i, j, 0);
}
} g[2];
vector<pi> p[4];
int main() {
rd(n), g[0].main(), g[1].main();
for (int i = 0; i < n * 2; i++)
for (int j = 0; j < n * 2; j++)
p[g[1].c[i][j]*2+g[0].c[i][j]].pb(mp(i, j));
int o = 0;
for (int i = 1; i < 4; i++)
if (p[i].size() > p[o].size()) o = i;
while ((int)p[o].size() > n * n) p[o].pop_back();
for (pi x : p[o]) print(x.fi, x.se);
return 0;
} | #include <iostream>
#include <cstdio>
#define il inline
#define ri register
using namespace std;
int main(){
//freopen("in","r",stdin);
//freopen("out","w",stdout);
int n,d1,d2;
scanf("%d%d%d",&n,&d1,&d2);
int a[4]{},n1(n<<1),b1(0),b2(0);
for(int i(d1);~i&1;++b1,i>>=1);
for(int i(d2);~i&1;++b2,i>>=1);
for(int i(0),j;i<n1;++i)
for(j=0;j<n1;++j)
++a[(b1&1?i:j-i)>>(b1>>1)&1|((b2&1?i:j-i)>>(b2>>1)&1)<<1];
int b3(0);
for(int i(0);i<4;++i)if(a[b3]<a[i])b3=i;
for(int i(0),j,i1(0);i<n1;++i)
for(j=0;j<n1;++j)
if(((b1&1?i:j-i)>>(b1>>1)&1|((b2&1?i:j-i)>>(b2>>1)&1)<<1)==b3){
printf("%d %d\n",i,j);
if(++i1==n*n)return 0;
}
return 0;
}
| 1 |
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int N, K;
const ll MOD = 998244353;
ll F[4002], F_inv[4002];
ll modpow(ll a, ll b) {
ll rtn = 1, kakeru = a;
while (b > 0) {
if (b & 1)rtn *= kakeru;
kakeru *= kakeru;
kakeru %= MOD;
rtn %= MOD;
b >>= 1;
}
return rtn;
}
void calc_fac() {
F[0] = 1, F[1] = 1;
for (int i = 2; i <= 4001; i++) {
F[i] = F[i - 1] * i;
F[i] %= MOD;
}
F_inv[4001] = modpow(F[4001], MOD - 2);
for (int j = 4000; j >= 0; j--) {
F_inv[j] = F_inv[j + 1] * (j + 1);
F_inv[j] %= MOD;
}
}
ll comb(ll a, ll b) {
if (a < 0)return 0;
if (b < 0)return 0;
if (b > a)return 0;
ll ans = (F[a] * F_inv[b])%MOD * F_inv[a - b];
return ans % MOD;
}
ll hcomb(ll a, ll b) {
return comb(a + b - 1, b);
}
int main() {
calc_fac();
cin >> K >> N;
for (int i = 2; i <= 2 * K; i++) {
if (i % 2 == 1) {
ll cnt = 0;
int A = min((i - 1) / 2, (2 * (K + 1) - i) / 2);
for (int j = 0; j <= A; j++) {
ll tmp = 1;
tmp *= (modpow(2, j) * comb(A, j)) % MOD;
tmp *= hcomb(K - 2 * A + j, N - j);
tmp %= MOD;
cnt += tmp;
cnt %= MOD;
}
cout << cnt << endl;
}
else {
ll cnt = 0;
int A = min((i) / 2, (2 * (K + 1) - i) / 2) - 1;
for (int j = 0; j <= A; j++) {
ll tmp = 1;
tmp *= (modpow(2, j) * comb(A, j)) % MOD;
ll a = hcomb(K - 2 * A + j - 1, N - j) + hcomb(K - 2 * A + j - 1, N - j - 1);
a %= MOD;
tmp *= a;
tmp %= MOD;
cnt += tmp;
cnt %= MOD;
}
cout << cnt << endl;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
char cc = getchar() ; int cn = 0, flus = 1 ;
while( cc < '0' || cc > '9' ) { if( cc == '-' ) flus = - flus ; cc = getchar() ; }
while( cc >= '0' && cc <= '9' ) cn = cn * 10 + cc - '0', cc = getchar() ;
return cn * flus ;
}
const int N = 4000 + 5 ;
const int P = 998244353 ;
int maxn, n, K, C[N][N], Ans[N] ;
signed main()
{
K = gi(), n = gi(), maxn = n + K ;
C[0][0] = 1 ;
rep( i, 1, maxn ) rep( j, 0, maxn ) C[i][j] = (!j) ? 1 : ( C[i - 1][j - 1] + C[i - 1][j] ) % P ;
for( re int i = 2; i <= 2 * K; ++ i ) {
int u = 0, v = 0 ;
rep( j, 1, K )
if( ((i - j) != j) && ( (i - j) <= K ) && ( (i - j) >= 1 ) ) ++ u ;
else if( (i - j) != j ) ++ v ;
u /= 2, v += u ;
if( i % 2 == 0 ) ++ u ;
for( re int j = 0; j <= n; ++ j ) {
Ans[i] = ( Ans[i] + C[u][j] * C[(n - j) + v - 1][(n - j)] % P ) % P ;
}
}
rep( i, 2, 2 * K ) printf("%lld\n", Ans[i] ) ;
return 0 ;
} | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#define ll long long
using namespace std;
int main()
{
double n;
cin >> n;
double ave=0;
vector<double> a(n);
for (ll i =0; i < n;i++){
cin >> a[i];
ave += a[i];
}
ave /= n;
//cout << ave << endl;
ll ans = n - 1;
for (ll i = n - 1; i >= 0; i--)
{
if(abs(a[ans]-ave)>=abs(a[i]-ave)){
ans = i;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n; cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
double average = (double)accumulate(a.begin(), a.end(), 0)/n;
int ans = 0;
double minv=100100100;
rep(i, n) {
if (abs(average-(double)a[i])< minv) {
ans = i;
minv = abs(average-(double)a[i]);
}
}
cout << ans << endl;
//cout << a[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 <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 = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
ll n;
string s;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> s;
map<pair<string,string>,ll> count;
rep(bit,1<<n){
string s1,t1;
rep(i,n){
if (bit&(1<<i)){
s1 += s[i+n];
}
else{
t1 += s[i+n];
}
}
reverse(all(t1));
count[make_pair(t1,s1)]++;
}
ll ans = 0;
rep(bit,1<<n){
string s1,t1;
rep(i,n){
if (bit&(1<<i)){
s1 += s[i];
}
else{
t1 += s[i];
}
}
reverse(all(t1));
ans += count[make_pair(s1,t1)];
}
PRINT(ans);
}
| #include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const int mod = (int)1e9 + 7;
const int mod2 = 998244353;
ll exp(ll taban, ll us) {
ll carpan = taban % mod;
ll temp = us;
ll res = 1;
while(temp){
if(temp % 2) res = (res*carpan) % mod;
temp /= 2;
carpan = (carpan*carpan) % mod;
}
return res;
}
ll ebob(ll a, ll b){
if(!a)return b;
return ebob(b%a, a);
}
ll ekok(ll a, ll b){
return (a*b)/ebob(a, b);
}
ll fact[(int)2e5+5];
ll komb(ll a, ll b){
return fact[a+b] * exp(fact[a]*fact[b], mod-2) % mod;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
fact[0] = 1;
for(int i = 1; i <= 2e5; i++) fact[i] = (fact[i-1]*i) % mod;
int n, m; cin>>n>>m;
unordered_map<int, int> cnt;
for(int i = 2; i*i <= m; i++){
while(m % i == 0){
m /= i;
cnt[i]++;
}
}
if(m > 1) cnt[m]++;
ll ans = 1;
for(auto x: cnt){
ans = (ans * komb(n-1, x.second)) % mod;
}
cout<<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int X,Y;
cin >> X >> Y;
int ans=0;
vector<int> a={0,300000,200000,100000};
if(X<=3) ans+=a.at(X);
if(Y<=3) ans+=a.at(Y);
if(X==1 && Y==1) ans+=400000;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int x, y;
cin >> x >> y;
--x, --y;
int c[] = { 300000, 200000, 100000, 0 };
cout << c[min(x, 3)] + c[min(y, 3)] + (!x && !y ? 400000 : 0) << endl;
return (0);
}
| 1 |
#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 101
#define MIN -100001
#define _MAX 8
int main(void)
{
char roman[102];
char fig[8] = { "IVXLCDM" };
int value[7] = { 1,5,10,50,100,500,1000 };
int sum = 0, b = _MAX;
while (scanf_s("%s", &roman, MAX) != EOF) {
for (int i = 0; roman[i] != '\0'; ++i) {
for (int j = 0; j < 8; ++j) {
if (roman[i] == fig[j]) {
if (b >= j) sum += value[j];
else { sum -= value[b]; sum += value[j] - value[b]; }
b = j;
}
}
}
printf("%d\n", sum);
sum = 0; b = _MAX;
}
} | #include <iostream>
using namespace std;
int convert( char c )
{
switch ( c )
{
case 'I': return 1;
case 'V': return 5;
case 'X': return 10;
case 'L': return 50;
case 'C': return 100;
case 'D': return 500;
case 'M': return 1000;
}
}
int main( void )
{
string input;
int answer, prev;
while ( cin >> input )
{
answer = 0;
prev = 0;
for ( string ::reverse_iterator it = input.rbegin(); it != input.rend(); it++ )
{
int next = convert( *it );
if ( prev <= next )
{
answer += next;
}
else
{
answer -= next;
}
prev = next;
}
cout << answer << endl;
}
return 0;
} | 1 |
#include<iostream>
#include<string>
using namespace std;
int main(){
string a,b,c;
int ca=0,cb=0,cc=0,flag=0,ans=0;
cin>>a>>b>>c;
for(int i=0;i<a.size()+b.size()+c.size();i++){
if(flag==0){
if(ca==a.size()){
ans=1;
break;
}
if(a[ca]=='a')flag=0;
if(a[ca]=='b')flag=1;
if(a[ca]=='c')flag=2;
ca++;
}
else if(flag==1){
if(cb==b.size()){
ans=2;
break;
}
if(b[cb]=='a')flag=0;
if(b[cb]=='b')flag=1;
if(b[cb]=='c')flag=2;
cb++;
}
else if(flag==2){
if(cc==c.size()){
ans=3;
break;
}
if(c[cc]=='a')flag=0;
if(c[cc]=='b')flag=1;
if(c[cc]=='c')flag=2;
cc++;
}
}
if(ans==1)cout<<"A"<<endl;
if(ans==2)cout<<"B"<<endl;
if(ans==3)cout<<"C"<<endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
using namespace std;
int main() {
vector<queue<char>> v(3);
string s;
rep(i, 0, 3) {
cin >> s;
for (char c : s) {
v[i].push(c);
}
}
int tmp, x = 0;
while (true) {
if (v[x].empty()) {
break;
}
tmp = x;
x = v[x].front() - 'a';
v[tmp].pop();
}
cout << char(x + 'A') << endl;
getchar();
} | 1 |
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
LL pw[87];
LL dfs(int i, LL d, int fg) {
if (i == 0) return d == 0 ? 1 : 0;
if (i == 1) return d == 0 ? 10 : 0;
LL D = (10 - (d % 10)) % 10;
//printf("i = %d d = %lld D = %lld\n", i, d, D);
LL c = 9 - D + 1 - fg;
d = d - pw[i - 1] * D + D;
return c * dfs(i - 2, abs(d) / 10, 0);
}
int main() {
LL D;
while (~scanf("%lld", &D)) {
LL ans = 0;
pw[0] = 1;
for (int i = 1; i <= 18; i++) {
pw[i] = pw[i - 1] * 10;
}
for (int i = 1; i <= 18; i++) {
ans += dfs(i, D, 1);
}
printf("%lld\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d;
map < ll, ll > mp[20];
ll pw10[20];
ll coef[20];
ll gc[20];
int LEN = 0;
int val[25];
int val0[25];
ll solve(int where, ll need) {
//cout << where << " " << need << endl;
if (where == LEN) {
return (need == 0);
}
if (gc[where] != 0 && need % gc[where] != 0) return 0;
//if (need % gc[where] != 0) return 0;
if (coef[where] == 0) {
if (need == 0) return 10;
else return 0;
}
if (mp[where].find(need) != mp[where].end()) {
return mp[where][need];
}
ll tot = 0;
for (int i = -9; i <= 9; i++) {
if (where) tot += solve(where + 1, need - i * coef[where]) * val[i + 9];
else {
tot += solve(where + 1, need - i * coef[where]) * val0[i + 9];
}
}
return mp[where][need] = tot;
}
ll solve(int len) {
LEN = (len + 1) / 2;
for (int i = 0; i <= LEN; i++) mp[i].clear();
for (int i = 0; i < (len + 1) / 2; i++) {
coef[i] = pw10[len - 1 - i] - pw10[i];
coef[i] /= 9;
}
gc[LEN] = 0;
for (int i = LEN - 1; i >= 0; i--) gc[i] = __gcd(coef[i], gc[i + 1]);
return solve(0, d);
}
int main() {
ios_base::sync_with_stdio(false);
//freopen("input.txt", "r", stdin);
for (int i = 0; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
val[i - j + 9]++;
if (j) val0[i - j + 9]++;
}
}
pw10[0] = 1;
for (int i = 1; i <= 18; i++) pw10[i] = 10 * pw10[i - 1];
cin >> d;
if (d % 9 != 0) {
cout << 0;
return 0;
}
d /= 9;
ll f = 0;
for (int len = 2; len <= 18; len++) {
f += solve(len);
}
cout << f << endl;
return 0;
}
| 1 |
#include <iostream>
using namespace std;
const int MAX_N = 100005;
int n, A[MAX_N], B[MAX_N], C[MAX_N], pos[3 * MAX_N], rev[3 * MAX_N];
void wypisz() {
cout << "----------------------\n";
for(int i = 1; i <= n; i++) cout << A[i] << " ";
cout << endl;
for(int i = 1; i <= n; i++) cout << B[i] << " ";
cout << endl;
for(int i = 1; i <= n; i++) cout << C[i] << " ";
cout << endl;
}
void swapColumn(int i) {
swap(A[i], C[i]);
}
int main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
for(int i = 1; i <= n; i++) cin >> B[i];
for(int i = 1; i <= n; i++) cin >> C[i];
for(int i = 1; i <= n; i++) {
if((B[i] % 3 != 2) || (((B[i] - 2) / 3) % 2 == i % 2)) {
cout << "No";
return 0;
}
int a = (A[i] - 1) / 3;
int b = (B[i] - 1) / 3;
int c = (C[i] - 1) / 3;
if(a != b || a != c || b != c) {
cout << "No";
return 0;
}
}
for(int i = 1; i <= n; i++) {
pos[B[i]] = i;
}
for(int i = 1; i <= n; i++) {
if(B[i] == 3 * i - 1) {
continue;
}
int j = pos[3 * i - 1];
int x = B[i];
int y = B[j];
B[i] = y;
B[j] = x;
swap(A[i], A[j]);
swap(C[i], C[j]);
pos[x] = j;
pos[y] = i;
if((i - j) % 4 != 0) {
swapColumn(i);
swapColumn(j);
}
swap(A[i + 1], C[i + 1]);
// wypisz();
}
int odd = 0, even = 0;
for(int i = 1; i <= n; i++) {
// if(rev[B[i]]) swap(A[i], C[i]);
if(A[i] > C[i]) {
if(i % 2 == 1) odd++;
else even++;
// cout << "No3";
// return 0;
}
}
if(odd % 2 == 1 || even % 2 == 1) {
cout << "No";
return 0;
}
cout << "Yes";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define read1(x) cin>>x
#define read2(x,y) cin>>x>>y
#define print(x) cout<<x<<endl
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vs vector<string>
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define vpii vector<pii>
#define umap unordered_map
#define uset unordered_set
#define clr(a,b) memset(a,b,sizeof a)
#define all(ds) ds.begin(), ds.end()
#define rev(ds) ds.rbegin(), ds.rend()
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<int>())
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof a)
#define fr(i, n) for(int i=0; i<n;++i)
#define fr1(i, n) for(int i=1; i<=n; ++i)
#define rfr(i, n) for(int i=n-1; i>=0; --i)
#define printVector(v) for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl;
#define precise(x) cout<<fixed<<setprecision(x)
#define inf 10000000000000
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }
ll power(ll x, ll y, ll m) { if(!y) return 1; ll p=power(x, y>>1, m)%m; p=p*p%m; return (y&1)?(x*p)%m:p;}
ll modInverse(ll a, ll m){ return power(a, m-2, m); }
bool isPrime(ll num){bool flag=true;for(ll i =2;i<=num/2;i++){if(num%i==0) {flag=false; break;} }return flag;}
ll sumofdigits(ll n){ll c=0;while(n>0){c++;n/=10;}return c;}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) {return a.first > b.first; }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) {return a.second < b.second; }
//const double PI= 2*acos(0.0);
const long long MOD= 1000000007;
void solve(){
int n; cin>>n;
vi v;
fr(i, n){
int x; cin>>x;
v.push_back(x);
}
sort(all(v));
if(v.size() <= 2){
print(0);
return;
}
int count = 0;
for(int i = 0; i < n-2; ++i){
for(int j = i+1; j < n-1; ++j){
if(v[i] == v[j])continue;
for(int k = j+1; k < n; ++k){
if(v[i] == v[k] || v[j] == v[k])continue;
if(v[i] + v[j] > v[k])count++;
}
}
}
cout<<count<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
input_output
#else
fastio
#endif
int t =1 ;
// cin>>t;
while(t--){
solve();
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[305][305][305];
string s;
int my(int l,int r,int k)
{
if (dp[l][r][k]!=0)
{
return dp[l][r][k];
}
else if (l==r)
{
dp[l][r][k]=1;
return 1;
}
else if (l+1==r)
{
if (s[l]==s[r]||k>0)
{
dp[l][r][k]=2;
return 2;
}
else
{
dp[l][r][k]=1;
return 1;
}
}
int ans=max(my(l+1,r,k),my(l,r-1,k));
if (s[l]==s[r])
{
ans=max(ans,my(l+1,r-1,k)+2);
}
else if (k>0)
{
ans=max(ans,my(l+1,r-1,k-1)+2);
}
dp[l][r][k]=ans;
return ans;
}
int main(int argc, char const *argv[])
{
int k;
cin>>s>>k;
cout<<my(0,s.size()-1,k)<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
ll Mod = 998244353;
const int N = 2e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll mul(ll a, ll b){
return (a * b) % Mod;
}
ll dp[3 * N][N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin >> n >> Mod;
dp[0][0] = 1;
for(int i = 1; i <= 3*n; i++){
for(int j = 0; j <= n; j++){
dp[i][j] = dp[i - 1][j];
if(j){
if(2 <= i) dp[i][j] += mul(i - 1, dp[i - 2][j - 1]);
if(3 <= i) dp[i][j] += mul(mul(i - 2, i - 1), dp[i - 3][j - 1]);
}
dp[i][j] %= Mod;
}
}
ll ans = 0;
for(int i = 0; i <= n; i++) ans += dp[3 * n][i];
cout << ans % Mod << '\n';
return 0;
}
| 0 |
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#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};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
string str,stra,ko;
ll x,y,w,z;
char hoge,fuga;
cin>>a>>b>>c>>d;
if(a+b>c+d) cout<<"Left"<<endl;
if(a+b==c+d) cout<<"Balanced"<<endl;
if(a+b<c+d) cout<<"Right"<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
string S;
cin >> S;
string T = S.substr(2, S.size()-3);
int count = 0;
rep(i, T.size()) if( T[i] == 'C' ) count++;
int o = 0;
rep(i, S.size()) if( S[i] < 'a' || S[i] > 'z' ) o++;
if( S.substr(0,1) == "A" && count == 1 && o == 2 ) cout << "AC" << endl;
else cout << "WA" << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
int main() {
ll A, B;
cin >> A >> B;
vector<ll> num_A;
vector<ll> num_B;
vector<ll> num;
num_A.push_back(1);
num_B.push_back(1);
for(int i = 2; i <= sqrt(A); i++){
if(A % i == 0){
while(A % i == 0){
A = A / i;
}
num_A.push_back(i);
}
}
num_A.push_back(A);
sort(num_A.begin(),num_A.end());
num_A.erase(unique(num_A.begin(), num_A.end()), num_A.end());
for(int i = 2; i <= sqrt(B); i++){
if(B % i == 0){
while(B % i == 0){
B = B / i;
}
num_B.push_back(i);
}
}
num_B.push_back(B);
sort(num_B.begin(),num_B.end());
num_B.erase(unique(num_B.begin(), num_B.end()), num_B.end());
for(int i = 0; i < num_A.size(); i++){
for(int j = 0; j < num_B.size(); j++){
if(num_A[i] == num_B[j]){
num.push_back(num_A[i]);
}
}
}
cout << num.size() << endl;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
ll power(ll x,ll y,ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
ll n,i,j,k,x,y,t,m;
cin >> x >> y;
ll ans=1;
n=x;
for(i=2;i*i<=x;i++)
{
if(n%i==0 && y%i==0)
ans++;
while(n%i==0)
n/=i;
}
if(n>1 && y%n==0)
ans++;
cout<<ans<<endl;
} | 1 |
#include <iostream>
using namespace std;
int main(){
int x, y;
cin >> x >> y;
if(x==1&&y==1){
cout << 1000000 << endl;
}else if(x==1&&y==2) {
cout << 500000 << endl;
}else if(x==1&&y==3) {
cout << 400000 << endl;
}else if(x==2&&y==1) {
cout << 500000 << endl;
}else if(x==2&&y==1) {
cout << 500000 << endl;
} else if(x==2&&y==2) {
cout << 400000 << endl;
} else if(x==2&&y==3) {
cout << 300000 << endl;
} else if(x==3&&y==1) {
cout << 400000 << endl;
} else if(x==3&&y==2) {
cout << 300000 << endl;
} else if(x==3&&y==3) {
cout << 200000 << endl;
} else if(x<=3) {
cout << (4-x)*100000 << endl;
} else if(y<=3){
cout << (4-y)*100000 << endl;
} else {
cout << 0 << endl;
}
return 0;
} | #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void) {
int X, Y;
scanf("%d %d", &X, &Y);
int award[] = {300000, 200000, 100000, 0};
if (X == 1 && Y == 1) printf("1000000\n");
else printf("%d\n", award[min(3, X - 1)] + award[min(3, Y - 1)]);
return 0;
}
| 1 |
#include <iostream>
#include <vector>
using namespace std;
void getResult(const uint actCount, uint *cookie1, uint *cookie2){
uint *first = cookie1;
uint *second = cookie2;
for(uint i = 0; i < actCount; i++){
if(*first % 2 != 0){
(*first)--;
}
uint half = *first / 2;
*first = half;
*second += half;
uint *tmp = first;
first = second;
second = tmp;
}
}
int main(){
uint A, B, K;
cin >> A >> B >> K;
getResult(K, &A, &B);
cout << A << " " << B;
return 0;
} | #include <iostream>
#include <iomanip>
#include <cmath>
int main(int argc, char const* argv[])
{
double x1, y1, x2, y2;
std::cin >> x1 >> y1 >> x2 >> y2;
double x = std::abs( x1 - x2 );
double y = std::abs( y1 - y2 );
std::cout << std::setprecision(20) << std::sqrt( x * x + y * y ) << std::endl;
return 0;
} | 0 |
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <atcoder/all>
#define F first
#define S second
#define int long long
#define ll long long
//#define int unsigned long long
#define pb push_back
//#define double long double
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
typedef tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3000000;
const int K = 100000;
const int mod = 1e9 + 7;
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, q;
cin >> n >> q;
fenwick_tree<int> f(n);
for (int i = 0; i < n; i++){
int x;
cin >> x;
f.add(i, x);
}
while(q--){
int t, l, r;
cin >> t >> l >> r;
if (t == 0){
f.add(l, r);
} else{
cout << f.sum(l, r) << endl;
}
}
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
template<class G>
class Fenwick_tree{
vector<G> a;
public:
Fenwick_tree(){}
Fenwick_tree(int n){ build(n); }
Fenwick_tree(const vector<G>& a){ build(a); }
void build(int n){
a.assign(n,G{});
}
void build(const vector<G>& a){
this->a=a;
for(int i=1;i<a.size();i++) if(i+(i&-i)-1<a.size()) (this->a)[i+(i&-i)-1]+=(this->a)[i-1];
}
void add(int i,const G& val){
for(i++;i<=a.size();i+=i&-i) a[i-1]+=val;
}
G sum(int l,int r)const{
if(l==0){
G res{};
for(;r>0;r-=r&-r) res+=a[r-1];
return res;
}
return sum(0,r)-sum(0,l);
}
int lower_bound(G val)const{
if(val<=G{}) return 0;
int x=0,k;
for(k=1;k<=a.size();k<<=1);
for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k;
return x;
}
int upper_bound(G val)const{
if(val<G{}) return 0;
int x=0,k;
for(k=1;k<=a.size();k<<=1);
for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k;
return x;
}
};
int main(){
int n,q; scanf("%d%d",&n,&q);
vector<lint> a(n);
rep(i,n) scanf("%lld",&a[i]);
Fenwick_tree<lint> F(a);
rep(_,q){
int t,l,r; scanf("%d%d%d",&t,&l,&r);
if(t==0) F.add(l,r);
else printf("%lld\n",F.sum(l,r));
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int H, W, ans=1; cin >> H >> W; string A[H];
REP(i, H){ cin >> A[i]; }
int B[H][W]={}; vector< pair<int, int> > C;
REP(i, H){ REP(j, W){
if(A[i][j]=='#'){ B[i][j]=1; C.push_back(make_pair(i, j)); }
} }
REP(i, H*W){
if((int)C.size()==H*W){ cout << ans-1 << "\n"; return 0; }
int a=C[i].first, b=C[i].second, c=B[a][b]+1;
if(a>0&&!B[a-1][b]){ B[a-1][b]=c; C.push_back(make_pair(a-1, b)); }
if(b>0&&!B[a][b-1]){ B[a][b-1]=c; C.push_back(make_pair(a, b-1)); }
if(a<H-1&&!B[a+1][b]){ B[a+1][b]=c; C.push_back(make_pair(a+1, b)); }
if(b<W-1&&!B[a][b+1]){ B[a][b+1]=c; C.push_back(make_pair(a, b+1)); }
ans=c;
}
} | #include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[1005];
const int DR[4] = {0, 1, 0, -1};
const int DC[4] = {1, 0, -1, 0};
int sp[1005][1005];
int main() {
int h, w;
scanf("%d%d", &h, &w);
memset(sp, -1, sizeof(sp));
queue<pair<int, int>> Q;
for (int i = 0; i < h; ++i) {
scanf("%s", str);
for (int j = 0; j < w; ++j) {
if (str[j] == '#') {
sp[i][j] = 0;
Q.push({i, j});
}
}
}
int ans = 0;
while (!Q.empty()) {
auto x = Q.front();
Q.pop();
ans = sp[x.first][x.second];
for (int d = 0; d < 4; ++d) {
int nr = x.first + DR[d];
int nc = x.second + DC[d];
if (nr < 0 || nc < 0 || nr >= h || nc >= w) continue;
if (sp[nr][nc] != -1) continue;
sp[nr][nc] = sp[x.first][x.second] + 1;
Q.push({nr, nc});
}
}
printf("%d\n", ans);
}
| 1 |
/*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L
const ll mod = 1e9+7;
const ll inf = 1e18;
ll popcount(ll num){
num = num - ((num >> 1) & 0x55555555);
num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
vector<pair<ll,ll>> factor_arr;
void myfactor(ll num){
ll count = 0;
while (!(num % 2)) {
num >>= 1; count++;
}
if (count) factor_arr.push_back({2,count});
for (auto i = 3; i <= sqrt(num); i += 2) {
count = 0;
while (num % i == 0) {
count++;
num /= i;
}
if (count) factor_arr.push_back({i,count});
}
if (num > 2) factor_arr.push_back({num,1});
}
void virus(){
ll a,b,c;
cin>>a>>b>>c;
cout<<min({a+b,b+c,a+c});
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ll t=1;
//cin>>t;
while(t--){
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
//cout << "Time: "<<duration.count()<<endl;
//your code goes here
}
return 0;
} | //om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int main(){
ll a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<(a[0]+a[1]);
} | 1 |
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
int main(){
priority_queue<int,vector<int>,greater<int> > que;
string ss;
int c[5];
while(scanf("%d,%d,%d,%d,%d",&c[0],&c[1],&c[2],&c[3],&c[4])!=EOF){
int dt[14];
for(int i=0;i<14;i++){
dt[i]=0;
}
for(int i=0;i<5;i++){
que.push(c[i]);
}
while(!que.empty()){
for(int i=1;i<=13;i++){
if(que.top()==i)dt[i]++;
}
que.pop();
}
int onepair=0,threecard=0,straight=0,fourcard=0;
for(int i=1;i<14;i++){
if(dt[i]==2)onepair++;
if(dt[i]==3)threecard++;
if(dt[i]==4)fourcard++;
}
for(int i=5;i<14;i++){
if(dt[i-4]==1 && dt[i-3]==1 && dt[i-2]==1 && dt[i-1]==1 &&dt[i]==1)straight++;
if(i==13){
if(dt[10]==1 && dt[11]==1 && dt[12]==1 && dt[13]==1 &&dt[1]==1)straight++;
}
}
if(onepair==1){
if(threecard==1)cout<<"full house"<<endl;
else cout<<"one pair"<<endl;
}
else if(onepair==2)cout<<"two pair"<<endl;
else if(threecard==1){
if(onepair==1)cout<<"full house"<<endl;
else cout<<"three card"<<endl;
}
else if(fourcard==1)cout<<"four card"<<endl;
else if(straight==1)cout<<"straight"<<endl;
else cout<<"null"<<endl;
}
return 0;
} | #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 4 * N + 5;
int head[N], nxt[M], to[M], typ[M], ne, n;
void init(){
ne = 0;
memset(head, -1, n * sizeof head[0]);
}
void addEdge(int f, int t, int ty){
to[ne] = t;
typ[ne] = ty;
nxt[ne] = head[f];
head[f] = ne++;
}
void addBiEdge(int a, int b, int ty){
addEdge(a, b, ty);
addEdge(b, a, ty);
}
struct state{
int dis;
set<int> typs;
};
state node[N];
bool inQ[N];
int dij(){
priority_queue<pair<int, int> , vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.emplace(0, 0);
for(int i = 0 ; i < n ; ++i)
node[i].dis = (int)1e9;
node[0].dis = 0;
inQ[0] = true;
int cst, v;
while(pq.size()){
auto top = pq.top();
pq.pop();
int u = top.second;
int d = top.first;
inQ[u] = false;
if(node[u].dis < d)continue;
for(int e = head[u] ; ~e ; e = nxt[e]){
v = to[e];
cst = (node[u].typs.find(typ[e]) == node[u].typs.end());
if(node[u].dis + cst < node[v].dis){
inQ[v] = true;
node[v] = {node[u].dis + cst, {typ[e]}};
pq.emplace(node[v].dis, v);
}
else if(node[u].dis + cst == node[v].dis){
if(node[v].typs.find(typ[e]) != node[v].typs.end())continue;
node[v].typs.emplace(typ[e]);
if(!inQ[v])
pq.emplace(node[v].dis, v), inQ[v] = true;
}
}
}
if(node[n - 1].dis > n)
node[n - 1].dis = -1;
return node[n - 1].dis;
}
int main(){
IO;
int m;
scanf("%d %d", &n, &m);
init();
while(m--){
int u, v, ty;
scanf("%d %d %d", &u, &v, &ty);
addBiEdge(--u, --v, ty);
}
printf("%d\n", dij());
} | 0 |
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main(){
int i,r;
string s;
map<char,int>m;
for(m['I']=1,m['V']=5,m['X']=10,m['L']=50,m['C']=100,m['D']=500,m['M']=1000;getline(cin,s);cout<<r<<endl)for(i=r=0;i<s.size();i++)r+=m[s[i]]*(m[s[i]]<m[s[i+1]]?-1:1);
} | #include<iostream>
#include<string>
using namespace std;
int Roman_to_Arabia(char c){
if (c == 'I')return 1;
else if (c == 'V')return 5;
else if (c == 'X')return 10;
else if (c == 'L')return 50;
else if (c == 'C')return 100;
else if (c == 'D')return 500;
else if (c == 'M')return 1000;
else return 0;
}
int main(){
string roman;
int num;
while (cin >> roman){
num = 0;
for (int i = 0; i < roman.size(); ++i){
if (Roman_to_Arabia(roman[i]) < Roman_to_Arabia(roman[i + 1]))
num -= Roman_to_Arabia(roman[i]);
else
num += Roman_to_Arabia(roman[i]);
}
cout << num << endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
if (x == 0) return y;
return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
//べき//
ll squ(ll n, ll p, ll m){
if(p==0) return 1;
if(p%2==0){
ll t=squ(n, p/2, m);
return t*t%m;
}
return n*squ(n,p-1,m);
}
//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
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;
}
}
// 二項係数計算
ll COM(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//nが大
ll com(ll n,ll m){
if(n<m || n<=0 ||m<0){
return 0;
}
if( m==0 || n==m){
return 1;
}
ll k=1;
for(ll i=1;i<=m;i++){
k*=(n-i+1);
k%=MOD;
k*=modinv(i,MOD);
k%=MOD;
}
return k;
}
////////////////////////////////////////////////////////////////////
ll a[100005];
int judge(int n){
ll y;
ll b[100005];
ll ch=0;
for(int i=1;i<=n;i++){
if(i==1){y=a[1];
if(y%2){y--;
ch=1;
}
}
else{
if(a[i]%2){
ch++;
y=gcd(y,a[i]-1);
}
else{
y=gcd(y,a[i]);
}
}
if(a[i]==1){return 0;}
if(ch>=2){return 0;}
}
if(ch==0){return 0;}
if(y==1||y%2==1){return 0;}
ll sum=0;
for(int i=1;i<=n;i++){
if(a[i]%2==0){
b[i]=a[i]/y;}
else{
b[i]=(a[i]-1)/y;
}
if((a[i]-b[i])%2)sum++;
}
if(sum%2){return 0;}
for(int i=1;i<=n;i++){
a[i]=b[i];
}
return 1;
}
int main() {
ll n;
cin>>n;
ll sum=0;
rep(i, n){
cin>>a[i];
sum+=a[i];
}
if(n%2==0){
if(sum%2==0){
cout<<"Second"<<endl;
}
else{
cout<<"First"<<endl;
}
return 0;
}
if(sum%2==0){cout<<"First"<<endl;
return 0;}
ll inv=0;
for(int u=1;u<=50;u++){
if(judge(n)==1){
inv++;
}
else{
break;
}
}
if(inv%2){cout<<"First"<<endl;}
else{cout<<"Second"<<endl;}
return 0;
}
| #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,a[100005];
bool work(){
int num1=0,num2=0;
for(int i=1;i<=n;i++)
if(a[i]>1){
if(a[i]&1)
num1++;
else
num2++;
}
if(!num1&&!num2)
return false;
if(num2&1)
return true;
if(num1>1||!num1)
return false;
for(int i=1;i<=n;i++)
if(a[i]>1&&a[i]&1){
a[i]--;
break;
}
int d=a[1];
for(int i=2;i<=n;i++)
d=__gcd(d,a[i]);
for(int i=1;i<=n;i++)
a[i]/=d;
return !work();
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
puts(work()?"First":"Second");
return 0;
} | 1 |
#include <cstdio>
#include <cstring>
using namespace std;
int main(void)
{
int n;
char str[10000],c;
char *t;
scanf("%d\n", &n);
for(int i = 0; i < n; i++){
gets(str);
while(t=strstr(str, "Hoshino"),t){
t[6] = 'a';
}
printf("%s\n", str);
}
return 0;
} | #include<iostream>
#include<string>
using namespace std;
int main(){
int n,pos;
string s;
while(cin>>n&&n){
getline(cin,s);
while(n--){
getline(cin,s);
while((pos=s.find("Hoshino",0))!=string::npos)
s.replace(pos,7,"Hoshina");
cout<<s<<endl;
}
}
return 0;
} | 1 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
template<class T>using vv = vector<vector<T>>;
using vvi = vv<int>;
using vvl = vv<long long>;
#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define repi(i,a,b) for(int i=(a),_i=(b);i<_i;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}
#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
int N;
vv<int> A;
ll dp[1<<16][16];
const ll INF = 1e15;
ll dfs(int used, int i) {
if (i == N)
return 0;
if (dp[used][i] != INF)
return dp[used][i];
if (used & (1 << i))
return dfs(used, i+1);
ll ans = 0;
vi notUsed;
rep(j, N)
if (!(used & (1 << j))) {
if (j < i)
return -INF;
notUsed.push_back(j);
}
rep(bit, 1 << (notUsed.size())) {
ll tmp = 0;
int used2 = 0;
rep(j, notUsed.size()) {
if (bit & (1 << j)) {
used2 |= 1 << notUsed[j];
rep(k, j+1, notUsed.size()) {
if (bit & (1 << k))
tmp += A[notUsed[j]][notUsed[k]];
}
}
}
ans = max(ans, tmp + dfs(used | used2, i+1));
}
return dp[used][i] = ans;
}
int main() {
in(N);
A.resize(N, vector<int>(N, 0));
rep(i, 1<<16) rep(j, 16) dp[i][j] = INF;
rep(i, N) rep(j, N) {
cin >> A[i][j];
}
cout << dfs(0, 0) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
using ll = long long;
using namespace std;
void chmax(ll &a, ll b){ if(a < b) a = b; return; }
ll n, a[16][16], dp[1<<16];
int main(){
cin >> n;
rep(i,n) rep(j,n) cin >> a[i][j];
loop(i,1,1<<n){
rep(j,n) rep(k,j) if(i>>j & i>>k & 1) dp[i] += a[j][k];
for(int j = i; j > 0; j = (j-1)&i) chmax(dp[i], dp[j]+dp[i^j]);
}
cout << dp[(1<<n)-1] << endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int,int>;
int main(){
int N, K;
cin >> N >> K;
int ans = 0;
for(int i = 1; i <= N - K + 1; ++i) {
ans++;
}
cout << ans << endl;
}
| #include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int main()
{
// freopen("input.txt","r",stdin);
int n,k;
cin>>n>>k;
cout<<n-(k-1)<<endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
void solve()
{
string s;cin>>s;
if(s=="MON")
cout<<6<<endl;
else if(s=="TUE")
cout<<5<<endl;
else if(s=="WED")
cout<<4<<endl;
else if(s=="THU")
cout<<3<<endl;
else if(s=="FRI")
cout<<2<<endl;
else if(s=="SAT")
cout<<1<<endl;
else
cout<<7<<endl;
}
int32_t main()
{
rapido;
int t;
//cin>>t;
t=1;
while(t--)
solve();
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<vector<int> > ivve;
#define sp ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define GCD(x,y) __gcd(x,y)
#define lb lower_bound
#define up upper_bound
#define setp setprecision
#define bs binary_search
#define all(x) x.begin(),x.end()
#define LCM(x,y) ((x*y)/__gcd(x,y))
#define spc(x) cout<<fixed<<setp(x)
const long long inf = 1e18;
const long long cs = 200005;
const long long mod = 1000000007;
const double PI = 2 * acos(0.0);
void solve()
{
ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
bool flag = false;
string s;
vector<string>v{"SUN","MON","TUE","WED","THU","FRI","SAT"};
cin>>s;
vector<string>::iterator it;
it=find(all(v),s);
x=distance(v.begin(),it);
cout<<7-x<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// freopen ("input.txt","r",stdin);
// freopen ("output.txt","w",stdout);
// int32_t tc;
// cin>>tc;
// while(tc--)
solve();
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
int main(){
ll k; cin>>k;
vector<ll> ans;
rep(i,51) if(i!=50-k%50) ans.push_back(k/50+i);
cout<<50<<endl;
puti(ans);
return 0;
}
| #include <iostream>
#define INF 1e9
using namespace std;
long long cnt;
void merge(int A[],int L,int M,int R){
int n1=M-L;
int n2=R-M;
int a[500000],b[500000];
for(int i=0;i<n1;i++)a[i]=A[L+i];
for(int i=0;i<n2;i++)b[i]=A[M+i];
a[n1]=INF,b[n2]=INF;
int i=0,j=0;
for(int k=L;k<R;k++){
if(a[i]<=b[j]) A[k]=a[i++];
else A[k]=b[j++],cnt+=(n1-i);
}
}
void mergeSort(int A[],int L,int R){
if(L+1<R){
int M=(L+R)/2;
mergeSort(A,L,M);
mergeSort(A,M,R);
merge(A,L,M,R);
}
}
int main(){
int n, a[500000];
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
mergeSort(a,0,n);
cout <<cnt<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
int main(){
string s;
cin >> s;
rep(i, s.size()-1){
if (s[i] == 'A' && s[i+1] == 'C'){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int r;
cin >> r;
if (r < 1200) cout << "ABC" << endl;
else if (r < 2800) cout << "ARC" << endl;
else cout << "AGC" << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
inline void read(long long &x) {
char ch;
bool flag = false;
for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
x = flag ? -x : x;
}
inline void write(long long x) {
static const long long maxlen = 100;
static char s[maxlen];
if (x < 0) { putchar('-'); x = -x;}
if (!x) { putchar('0'); return; }
long long len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';
for (long long i = len - 1; i >= 0; --i) putchar(s[i]);
}
inline void read(int &x){
char ch;
bool flag = false;
for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
x = flag ? -x : x;
}
const long long MAXN =1001000;
long long n;
struct kt{
long long x,y;
long long id;
}a[ MAXN ];
long long fa[ MAXN ];
struct edge{
long long x,y,val;
}E[ MAXN*2 ];
bool cmp_x(kt A,kt B){
return A.x<B.x;
}
bool cmp_y(kt A,kt B){
return A.y<B.y;
}
bool cmp_e(edge A,edge B){
return A.val<B.val;
}
long long get_fa(long long x){
return (fa[x]==x)?(x):(fa[x]=get_fa(fa[x]));
}
int main(){
read(n);
for (long long i=1;i<=n;i++)
{
a[i].id=i;
read(a[i].x);read(a[i].y);
}
sort(a+1,a+n+1,cmp_x);
long long cnt=0;
for (long long i=1;i<n;i++)
{
++cnt;
E[cnt].x=a[i].id;
E[cnt].y=a[i+1].id;
E[cnt].val=a[i+1].x-a[i].x;
}
sort(a+1,a+n+1,cmp_y);
for (long long i=1;i<n;i++)
{
++cnt;
E[cnt].x=a[i].id;
E[cnt].y=a[i+1].id;
E[cnt].val=a[i+1].y-a[i].y;
}
for (long long i=1;i<=n;i++)
fa[i]=i;
sort(E+1,E+cnt+1,cmp_e);
long long ans=0;
for (long long i=1;i<=cnt;i++)
{
long long a=E[i].x,b=E[i].y;
long long x=get_fa(a),y=get_fa(b);
if ( x!=y )
{
ans+=E[i].val;
fa[x]=y;
}
}
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.141592653589793
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
/*
* UnionFind。O(アッカーマン)
*/
struct UnionFind{
vi p;
UnionFind(int s):p(s,-1){}
void unite(int a,int b){
a=root(a);b=root(b);
if(a!=b){
if(p[b]<p[a])swap(a,b);
p[a]+=p[b];p[b]=a;
}
}
bool same(int a,int b){return root(a)==root(b);}
int root(int a){return p[a]<0?a:p[a]=root(p[a]);}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
using D=tuple<int,int,int>;
vector<D> data;
rep(i,n){
int x,y;
cin>>x>>y;
data.emplace_back(i,x,y);
}
vector<D> edge;
sort(all(data),[](D a,D b){return get<1>(a)<get<1>(b);});
rep(i,n-1){
int a0,a1,a2,b0,b1,b2;
tie(a0,a1,a2)=data[i];
tie(b0,b1,b2)=data[i+1];
edge.emplace_back(b1-a1,a0,b0);
}
sort(all(data),[](D a,D b){return get<2>(a)<get<2>(b);});
rep(i,n-1){
int a0,a1,a2,b0,b1,b2;
tie(a0,a1,a2)=data[i];
tie(b0,b1,b2)=data[i+1];
edge.emplace_back(b2-a2,a0,b0);
}
int ans=0;
UnionFind uf(n);
sort(all(edge),[](D a,D b){return get<0>(a)<get<0>(b);});
for(auto&e:edge){
int c,a,b;
tie(c,a,b)=e;
if(uf.same(a,b))continue;
uf.unite(a,b);
ans+=c;
}
cout<<ans<<endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>
map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;
int main()
{
ll t, n, x;
scl(n);
ll mn = 1e10, d;
for (ll i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
d = max(i, n / i);
ll cnt = 0;
while (d >= 1)
{
d /= 10;
cnt++;
}
mn = min(cnt, mn);
}
}
pcl(mn);
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>
using namespace std;
#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n) for(int i=0; i<(int) (n); i++)
typedef pair<int, int> P;
const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
for (int i = 0; i < vec.size(); i++) {
cin >> vec[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;
}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
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;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
long long modpow(int a, int n) {
int res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
bool chmax(int& xx, int yy) {
if (xx < yy) {
xx = yy;
return true;
}
return false;
}
bool chmin(int& xx, int yy) {
if (xx > yy) {
xx = yy;
return true;
}
return false;
}
int gcd(int xx, int yy) {
int p = xx;
int q = yy;
if (q > p)swap(p, q);
while (p % q != 0) {
p %= q;
swap(p, q);
}
return q;
}
int lcm(int xx, int yy) {
return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
if (xx <= 1) {
return 0;
}
for (int i = 2; i * i <= xx; i++) {
if (xx % i == 0) {
return 0;
}
}
return 1;
}
signed main() {
int n,mi=INF,ans=1;
cin >> n;
for (int i = 1; i*i <= n; i++) {
if (n % i == 0) {
chmin(mi,n / i);
}
}
if (mi == INF)mi = n;
while (mi >= 10) {
mi /= 10;
ans++;
}
cout << ans << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int64_t ans = 0;
vector<int> a(n);
for(int i=0; i<n; i++) {
cin >> a[i];
if(i>=1) {
ans += max(0, a[i-1]-a[i]);
if(a[i-1]-a[i]>0) a[i] = a[i-1];
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct UnionFind{
vector<int> p;
UnionFind(int n){
p.resize(n);
for(int i=0; i<n; i++) p[i] = i;
}
int find(int x){
if(p[x] == x) return x;
return p[x] = find(p[x]);
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
p[x] = y;
}
};
int main(){
int n; cin >> n;
vector<tuple<int, int, int>> xyn(n); // 0:x 1:y 2:idenfi.. number
for(int i=0; i<n; i++){
cin >> get<0>(xyn[i]) >> get<1>(xyn[i]);
get<2>(xyn[i]) = i;
}
vector<tuple<int, int, int>> edge; // 0:cost 1:from 2:to
// x でソート
sort(xyn.begin(), xyn.end(), [](auto &a, auto &b){ return get<0>(a) < get<0>(b); });
for(int i=1; i<n; i++) // 隣接する2頂点を cost : x座標差で辺として格納
edge.push_back({get<0>(xyn[i])-get<0>(xyn[i-1]), get<2>(xyn[i-1]), get<2>(xyn[i])});
// y でソート
sort(xyn.begin(), xyn.end(), [](auto &a, auto &b){return get<1>(a) < get<1>(b); });
for(int i=1; i<n; i++) // 隣接する2頂点を cost : y座標差で辺として格納
edge.push_back({get<1>(xyn[i])-get<1>(xyn[i-1]), get<2>(xyn[i-1]), get<2>(xyn[i])});
sort(edge.begin(), edge.end()); // 辺たちをコストで昇順
long ans = 0;
// クラスカル法
UnionFind uf(n);
for(auto nowe : edge){
if(uf.find(get<1>(nowe)) == uf.find(get<2>(nowe))) continue;
uf.unite(get<1>(nowe), get<2>(nowe));
ans += get<0>(nowe);
}
cout << ans << endl;
return 0;
}
| 0 |
#include <iostream>
using namespace std;
int main() {
int N, Y;
cin >> N >> Y;
// 答えを格納するための変数
int ares = -1, bres = -1, cres = -1;
// 全探索
for (int a = 0; a <= N; ++a) {
// a + b が N 以下の範囲で
for (int b = 0; a + b <= N; ++b) {
int c = N - a - b;
if (10000 * a + 5000 * b + 1000 * c == Y) {
ares = a;
bres = b;
cres = c;
}
}
}
cout << ares << " " << bres << " " << cres << endl;
} | #include <bits/stdc++.h>
using namespace std;
void input(int& rnTrgSu, int& rnTrgKin)
{
cin >> rnTrgSu >> rnTrgKin;
}
void searchMoney(int nTrgSu, int nTrgKin)
{
vector<int> cnvnMoney{10000, 5000, 1000};
int nCalKin;
int i, j;
for (i = 0; i <= nTrgSu; i++)
{
for (j = 0; j <= (nTrgSu - i); j++)
{
nCalKin = nTrgKin;
nCalKin -= cnvnMoney[0] * i;
nCalKin -= cnvnMoney[1] * j;
nCalKin -= cnvnMoney[2] * (nTrgSu - i - j);
if ( !nCalKin )
break;
}
if ( !nCalKin )
break;
}
if ( !nCalKin )
cout << i << " " << j << " " << (nTrgSu - i - j) << endl;
else
cout << -1 << " " << -1 << " " << -1 << endl;
}
int main()
{
int nTrgSu, nTrgKin;
input(nTrgSu, nTrgKin);
searchMoney(nTrgSu, nTrgKin);
return 0;
} | 1 |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return -1;
}
template <typename T>
string make_string(T N)
{
string ret;
T now = N;
while (now > 0)
{
T x = now % 10;
ret += (char)('0' + x);
now /= 10;
}
reverse(all(ret));
return ret;
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b; // aをbで更新
return true;
}
return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
const string minf = "-";
void chmax(string &s, string t)
{
if (s == minf)
{
s = t;
return;
}
if (s.size() < t.size())
{
s = t;
return;
}
if (s.size() == t.size() && s < t)
{
s = t;
return;
}
return;
}
//cost[i]:iを作るのに必要なコスト
const ll cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main()
{
cout << fixed << setprecision(30);
ll N, M;
cin >> N >> M;
vector<ll> A(M);
loop(i, M) cin >> A[i];
vector<string> dp(11000, "-");
dp[0] = "";
loop(i, 10010)
{
if (dp[i] == minf)
continue;
loop(j, M)
{
ll nownum = cost[A[j]];
chmax(dp[i + nownum], dp[i] + (char)('0' + A[j]));
}
}
putout(dp[N]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int x[10] = {-1,2,5,5,4,5,6,3,7,6};
void chmax(int &a, const int &b) { if (a < b) a = b; return; }
int main(){
int n, m; cin >> n >> m;
vector<int> data(m);
for (int i = 0; i < m; i++) cin >> data[i];
sort(data.begin(),data.end(),greater<int>());
vector<int> keta(n+1,-1); keta[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - x[data[j]] >= 0) chmax(keta[i], keta[i - x[data[j]]] + 1);
}
}
while (n > 0) {
for (int i = 0; i < m; i++) {
if (n - x[data[i]] >= 0 && keta[n] == keta[n - x[data[i]]] + 1) {
cout << data[i];
n -= x[data[i]];
break;
}
}
}
return 0;
} | 1 |
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int n,m;
int P[1010],Q[1000000];
while(true){
cin >> n >> m;
if(n==0&&m==0) break;
P[0]=0;
for(int i=1;i<=n;i++) scanf("%d",&P[i]);
int num=0;
for(int i=0;i<=n;i++){
for(int j=i;j<=n;j++){
Q[num++]=P[i]+P[j];
}
}
sort(Q,Q+num);
int key,index,ans=0;
int *pos;
for(int i=0;i<num;i++){
key=m-Q[i];
if(key<0) break;
pos=lower_bound(Q,Q+num,key);
index=distance(Q,pos)-1;
ans=max(ans,Q[i]+Q[index]);
}
cout << ans << endl;
}
return 0;
} | #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"
using namespace std;
const long long int MOD = 1000000007;
int N, M;
int main() {
ios::sync_with_stdio(false);
cin >> N >> M;
while (N) {
int num[1001];
int ans = 0;
set<int>F;
set<int>S;
for (int i = 0; i < N; i++)cin >> num[i];
F.insert(0);
for (int i = 0; i < N/2; i++) {
F.insert(num[i]);
for (int j = 0; j < N/2; j++) {
F.insert(num[i] + num[j]);
}
}
S.insert(0);
for (int i = N/2; i < N; i++) {
S.insert(num[i]);
for (int j = N/2; j < N; j++) {
S.insert(num[i] + num[j]);
}
}
set<int>::reverse_iterator ritr = S.rbegin();
for (auto i : F) {
if (ritr == S.rend())break;
while ((i + *ritr) > M) {
++ritr;
if (ritr ==S.rend())break;
}
if(ritr!=S.rend()) ans = max(ans, i + *ritr);
}
cout << ans << endl;
cin >> N >> M;
}
return 0;
} | 1 |
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200010
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli;
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int N;
double pi=2.0*acos(0.0);
vector<pair<pair<double,double>,int> > data;
vi ans;
double calcvec(pair<double,double> hoge1,pair<double,double> hoge2){
double x=hoge2.first,y=hoge2.second;
x-=hoge1.first,y-=hoge1.second;
double ret=acos(x/sqrt(x*x+y*y));
if(y<0)ret=2.0*pi-ret;
return ret;
}
double calckaku(double a,double b){
double ret=b-a;
if(ret<0)ret+=2.0*pi;
return ret;
}
int main(){
cin>>N;
int lef=0;
for(int i=0;i<N;i++){
double x,y;
cin>>x>>y;
data.pb(mp(mp(x,y),i));
}
sort(data.begin(),data.end());
reverse(data.begin(),data.end());
int num=0,nxnum;
double kakub=acos(0.0);
while(1){
nxnum=0;
double mi=2.0*pi,kakumemo;
for(int i=0;i<N;i++){
if(i!=num){
double kaku=calcvec(data[num].first,data[i].first);
double kakuc=calckaku(kakub,kaku);
if(kakuc<mi){
mi=kakuc,nxnum=i,kakumemo=kaku;
}
}
}
ans.pb(num);
kakub=kakumemo;
if(nxnum==0)break;
num=nxnum;
}
double ans2[105]={0.0};
int n=ans.size();
for(int i=0;i<n;i++){
int n1=ans[i],n2=ans[((i+1)%n)],n0=ans[((i+n-1)%n)];
double ka1=calcvec(data[n1].first,data[n2].first);
double ka2=calcvec(data[n0].first,data[n1].first);
double ka=calckaku(ka2,ka1);
ans2[data[ans[i]].second]=ka/(2.0*pi);
}
for(int i=0;i<N;i++)printf("%.7lf\n",ans2[i]);
} | #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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int main() {
int N;
cin >> N;
vector<int> X(N), Y(N);
vector<char> U(N);
map<char, int> conv;
char conv_table[5] = "URDL";
REP(i, 4) conv[conv_table[i]] = i;
REP(i, N) {
char c;
scanf("%d %d %c", &X[i], &Y[i], &c);
U[i] = c;
}
map<int, vector<pii>> lr, ud, ru, rd;
REP(i, N) {
lr[Y[i]].emplace_back(X[i], U[i]);
ud[X[i]].emplace_back(Y[i], U[i]);
ru[X[i] - Y[i]].emplace_back(X[i], U[i]);
rd[X[i] + Y[i]].emplace_back(X[i], U[i]);
}
int ans = INF;
for (auto &it : lr) {
vector<pii> v = it.se;
vector<int> ord(v.size());
iota(ALL(ord), 0);
sort(ALL(ord), [&](int i, int j) {
return v[i].fi < v[j].fi;
});
int last = -INF;
for (int i : ord) {
if (v[i].se == 'R') last = v[i].fi;
else if (v[i].se == 'L' && last != -INF) chmin(ans, (v[i].fi - last) * 5);
}
}
for (auto &it : ud) {
vector<pii> v = it.se;
vector<int> ord(v.size());
iota(ALL(ord), 0);
sort(ALL(ord), [&](int i, int j) {
return v[i].fi < v[j].fi;
});
int last = -INF;
for (int i : ord) {
if (v[i].se == 'U') last = v[i].fi;
else if (v[i].se == 'D' && last != -INF) chmin(ans, (v[i].fi - last) * 5);
}
}
for (auto &it : ru) {
vector<pii> v = it.se;
vector<int> ord(v.size());
iota(ALL(ord), 0);
sort(ALL(ord), [&](int i, int j) {
return v[i].fi < v[j].fi;
});
int lastu = -INF, lastr = -INF;
for (int i : ord) {
if (v[i].se == 'U') lastu = v[i].fi;
else if (v[i].se == 'R') lastr = v[i].fi;
else if (v[i].se == 'D' && lastr != -INF) chmin(ans, (v[i].fi - lastr) * 10);
else if (v[i].se == 'L' && lastu != -INF) chmin(ans, (v[i].fi - lastu) * 10);
}
}
for (auto &it : rd) {
vector<pii> v = it.se;
vector<int> ord(v.size());
iota(ALL(ord), 0);
sort(ALL(ord), [&](int i, int j) {
return v[i].fi < v[j].fi;
});
int lastr = -INF, lastd = -INF;
for (int i : ord) {
if (v[i].se == 'R') lastr = v[i].fi;
else if (v[i].se == 'D') lastd = v[i].fi;
else if (v[i].se == 'U' && lastr != -INF) chmin(ans, (v[i].fi - lastr) * 10);
else if (v[i].se == 'L' && lastd != -INF) chmin(ans, (v[i].fi - lastd) * 10);
}
}
if (ans == INF) puts("SAFE");
else cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
int sum = 0;
while (n > 0) { // n が 0 になるまで
sum += n % 10;
n /= 10;
}
return sum;
}
int main(){
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
vector<int> scinence = {a,b,c,d};
vector<int> sorcial = {e,f};
sort(scinence.begin(), scinence.end());
int ans = 0;
for(int i = 3; i > 0;--i) ans += scinence.at(i);
ans += max(e,f);
cout << ans << endl;
}
| #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)
#define in cin
#define out cout
#define pb push_back
using namespace std;
int main(){
int a[4], b[2], mi = 999, sum=0;
REP(i, 4) {
in >> a[i];
sum += a[i];
mi = min(mi, a[i]);
}
in >> b[0];
in >> b[1];
int bb = max(b[0], b[1]);
sum -= mi;
out << sum+bb << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;
int main(){
double n,m,d;cin >>n>>m>>d;
double p;
if(d==0){
p=1/n;
}
else {
p=2*(n-d)/(n*n);
}
// cout <<p<<endl;
p*=(m-1);
cout <<setprecision(20)<<p<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b; // aをbで更新
return true;
}
return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b; // aをbで更新
return true;
}
return false;
}
int main(){
ll n, m, d;
cin >> n >> m >> d;
long double x = 0;
if(2 * d >= n){
x += n - d;
x += n - d;
x /= n * n;
}
else if(d == 0){
x += n;
x /= n * n;
}
else{
x += d;
x += 2 * (n - 2 * d);
x += d;
x /= n * n;
}
cout << fixed << setprecision(10);
cout << x * (m - 1) << endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
vector<int64_t>A(N);
for(int i=0;i<N;i++)
cin>>A.at(i);
vector<int64_t>B(1+N);
map<int64_t,int64_t>M;
M[1]=A.at(0);
for(int i=2;i<=N;i++)
if(i%2==1)
M[i]=M.at(i-2)+A.at(i-1);
B.at(0)=0;
B.at(0)=0;
B.at(2)=max(A.at(0),A.at(1));
for(int i=3;i<=N;i++){
if(i%2==0)
B.at(i)=max(A.at(i-1)+B.at(i-2),A.at(i-2)+M.at(i-3));
else
B.at(i)=max(A.at(i-1)+B.at(i-2),A.at(i-2)+B.at(i-3));
}cout<<B.at(N)<<endl;
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
int i, j, n, cnt=0;
cin >> n;
int A[n];
for (i = 0; i < n; i++) cin >> A[i];
for (i = 0; i < n; i++) {
for (j = n - 1; j > i; j--) {
if (A[j] < A[j-1]) {
swap(A[j], A[j-1]);
cnt++;
}
}
}
for (i = 0; i < n; i++) {
cout << A[i];
if (i == n - 1) cout << endl;
else cout << ' ';
}
cout << cnt << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
void into(){
scanf("%d",&n);
}
void work(){
}
void outo(){
printf("%d\n",(n-2)*180);
}
int main(){
into();
work();
outo();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
if ('0' <= c && c <= '9') return (c - '0');
return -1;
}
vector<int> input(int n) {
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
return vec;
}
void output(vector<int> vec) {
for (int i = 0; i < vec.size(); i++) {
cout << vec[i] << " ";
}
return;
}
vector<vector<int>> input(int n, int m) {
vector<vector<int>> table(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table. at(i).at(j);
}
}
return table;
}
void output(vector<vector<int>> table) {
for (int i = 0; i < table.size(); i++) {
for (int j = 0; j < table.at(0).size(); j++) {
cout << table.at(i).at(j) << " ";
}
cout << endl;
}
}
long long perm(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long perm = 1;
for (int i = n; i > n - r; i--) {
perm *= i;
}
return perm;
}
long long comb(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long comb = perm(n,r);
for (int i = r; i > 0; i--) {
comb /= i;
}
return comb;
}
long long homo(int n, int r) {
return comb(n + r - 1, n - 1);
}
long long fact(int n) {
long long fact = 1;
for (int i = n; i > 0; i--) {
fact *= i;
}
return fact;
}
int gcd(int a, int b){
if (a % b == 0){
return(b);
}else{
return(gcd(b, a % b));
}
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
bool isprime(int n){
if (n < 2) return false;
else if (n == 2) return true;
else if (n % 2 == 0) return false;
for (int i = 3; i <= sqrt(n); i += 2){
if (n % i == 0){
return false;
}
}
return true;
}
vector<long long> divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N/i != i) res.push_back(N/i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
return res;
/*long long N;
cin >> N;
vector<long long> res = divisors(N);
for (int i = 0; i < res.size(); ++i) {
cout << res[i] << " ";
}
cout << endl;*/
}
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1) res.push_back({N, 1});
return res;
}
void sayYes(bool f) {
if (f) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
void sayYES(bool f) {
if (f) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
int main() {
int n;
cin >> n;
cout << (n-2)*180 << endl;
}
| 1 |
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int n[102], tn=0,ni=0,all = 0, i = 0,h=0;
int data[1024][10];
int tdata[10] = { 0 };
//input
while (1){
cin >> n[ni];
if (n[ni] == 0)break;
tn += n[ni];
for (; i < tn; i++){
for (int j = 0; j < n[ni]; j++){
cin >> data[i][j];
}
}
ni++;
}
//output
for (int k = 0; k < ni; k++){
for (int i=0; i < n[k]; i++, all = 0,h++){
for (int j = 0; j < n[k]; j++){
printf("%5d", data[h][j]);
all += data[h][j];
tdata[j] += data[h][j];
}
printf("%5d\n", all);
}
all = 0;
for (int i = 0; i < n[k]; i++){
printf("%5d", tdata[i]);
all += tdata[i];
}
printf("%5d\n", all);
for (int i = 0; i < n[k]; i++){
tdata[i] = 0;
}
all = 0;
}
return 0;
} | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
int main(){
int N,Q,M,Date[101],i,l,k;
while(0<=scanf("%d%d",&N,&Q)){
for(i=0;i<101;i++){
Date[i]=0;
}
if((N==0) && (Q==0)){
break;
}
for(k=0;k<N;k++){
scanf("%d",&M);
if(M==0){
continue;
}else{
for(i=0;i<M;i++){
scanf("%d",&l);
++Date[l];
}
}
}
l=0;
i=0;
for(k=0;k<100;k++){
if(i<Date[k] && Date[k]>=Q){
i=Date[k];
l=k;
}
}
printf("%d\n",l);
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
bool f(vector<ll> &a) {
int N = (int)a.size();
if (*max_element(ALL(a)) < N)
return false;
REP(i, N) a[i]++;
*max_element(ALL(a)) -= (N+1);
return true;
}
void rev(vector<ll> &a) {
int N = (int)a.size();
REP(i, N) a[i]--;
*min_element(ALL(a)) += (N+1);
}
void print(const vector<ll> &a) {
int N = (int)a.size();
cout << N << endl;
REP(i, N) {
if (i > 0) cout << " ";
cout << a[i];
}
cout << endl;
}
int main2() {
ll K; cin >> K;
int N = 50;
vector<ll> a(N, N-1);
REP(i, N) a[i] += K/N;
REP(_, K % N) {
rev(a);
}
print(a);
// if (K <= 100) {
// ll count = 0;
// while (f(a)) {
// count++;
// print(a);
// }
// cout << "check=" << count << endl;
// }
return 0;
}
int main() {
for (;!cin.eof();cin>>ws)
main2();
return 0;
}
| # include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
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; };
# define ALL(qpqpq) (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw) sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe) transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr) transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy) for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu) FOR(i,0,upupu)
# define INIT std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)
class node {
public:
int key;
node *parent, *lch, *rch;
};
node *NIL, *root;
void insert(int v) {
node *y = NIL, *x = root, *z = new node;
z->key = v; z->lch = z->rch = NIL;
while (x != NIL) {
y = x;
if (z->key < x->key)x = x->lch;
else x = x->rch;
}
z->parent = y;
if (y == NIL)root = z;
else if (z->key < y->key)y->lch = z;
else y->rch = z;
return;
}
node* find(int k) {
node *x = root;
while (x != NIL&&k != x->key) {
if (k < x->key)x = x->lch;
else x = x->rch;
}
return x;
}
node* next(node *z) {
node *x, *y;
if (z->rch != NIL) {
x = z->rch;
while (x->lch != NIL)x = x->lch;
return x;
}
y = z->parent;
while (y != NIL&&x == y->rch) {
x = y;
y = y->parent;
}
return y;
}
void remove(node *z) {
node *y, *x;
if (z->lch == NIL || z->rch == NIL)y = z;
else y = next(z);
if (y->lch != NIL)x = y->lch;
else x = y->rch;
if (x != NIL)x->parent = y->parent;
if (y->parent == NIL)root = x;
else if (y == y->parent->lch)y->parent->lch = x;
else y->parent->rch = x;
if (y != z)z->key = y->key;
delete(y);
return;
}
void ino(node *u) {
if (u == NIL)return;
ino(u->lch);
cout << " " << u->key;
ino(u->rch);
return;
}
void preo(node *u) {
if (u == NIL)return;
cout << " " << u->key;
preo(u->lch);
preo(u->rch);
return;
}
void print() {
ino(root);
cout << endl;
preo(root);
cout << endl;
return;
}
int main() {
int n; cin >> n;
string s; node *a;
while (cin >> s) {
if (s == "insert") {
cin >> n;
insert(n);
}
else if (s == "find") {
cin >> n;
a = find(n);
if (a != NIL)cout << "yes" << endl;
else cout << "no" << endl;
}
else if (s == "delete") {
cin >> n;
remove(find(n));
}
else if (s == "print")print();
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (long long i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int n,m;
vector<int> v[501];
set<int> st,ss;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while(true) {
cin>>n>>m;
if(n==0&m==0) break;
REP(i,501) v[i].clear();
st.clear();ss.clear();
REP(i,m) {
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
st.insert(1);
REP(i,v[1].size()) {
st.insert(v[1][i]);
}
for(auto x:st) {
REP(i,v[x].size()) {
ss.insert(v[x][i]);
}
}
for(auto x:st) {
ss.insert(x);
}
cout<<ss.size()-1<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int n, ans = 0;
cin >> n;
vector<int> a(n);
vector<vector<int> > x(n), y(n);
rep(i, n){
cin >> a[i];
rep(j, a[i]){
int X, Y;
cin >> X >> Y;
X--;
x[i].push_back(X);
y[i].push_back(Y);
}
}
rep(bit, 1<<n){
bitset<16> tmp(bit);
if((int)tmp.count() < ans) continue;
bool ok = true;
rep(i, n) {
// 正直な人
if(tmp.test(i)){
rep(j, a[i]) {
// x[i][j]は正直者だと正直者が言っているのに実際には正直者ではない
if(tmp.test(x[i][j]) && y[i][j] == 0) {
ok = false;
break;
}
if(!tmp.test(x[i][j]) && y[i][j] == 1) {
ok = false;
break;
}
}
}
}
if(ok) chmax(ans, (int)tmp.count());
}
cout << ans << endl;
} | 0 |
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
cout << "2018/01/" << s.substr(s.size() - 2) << endl;
return 0;
}
| #include <stdio.h>
int main(){
int year;
int month;
int day;
scanf("%d/%d/%d", &year, &month, &day);
printf("2018/%02d/%02d\n", month, day);
return 0;
} | 1 |
//0017
#include <bits/stdc++.h>
using namespace std;
string str;
int find_str(){
if(str.find("the",0) != string::npos)
return 1;
if(str.find("this",0) != string::npos)
return 1;
if(str.find("that",0) != string::npos)
return 1;
return 0;
}
int main(){
int i,j;
while(getline(cin,str)){
for(i = 0;i < 26;i++){
for(j = 0;j < str.size();j++){
if('a'<=str[j]&&str[j]<='z'){
if(25<(int)str[j]+1-'a'){
str[j] = 'a';
}else{
str[j] = str[j] + 1;
}
}
}
if(find_str()){
cout<<str<<endl;
break;
}
}
}
return 0;
} | #include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int msg_size = 80;
const char int2alp[26] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z'
};
typedef map<char, int> myMap;
myMap alp2int;
int get_length(char *data) {
for (int i = 0;; i++) {
if (data[i] == '\0') {
return i;
}
}
}
bool is_match(char *data) {
for (int i = 0; i < 81; i++) {
if (data[i] == 't' && data[i+1] == 'h') {
if (data[i+2] == 'e') {
return true;
}
else if (data[i+2] == 'i' && data[i+3] == 's'){
return true;
}
else if (data[i+2] == 'a' && data[i+3] == 't') {
return true;
}
}
}
return false;
}
bool gen_caesar(char *data, int size, int length) {
char prev[100], back[100];
prev[length] = back[length] ='\0';
for (int i = 0; i < length; i++) {
if (data[i] == ' ' || data[i] == '.' || data[i] == '\n') {
prev[i] = data[i];
back[i] = data[i];
}
else {
prev[i] = int2alp[(alp2int[data[i]]+size) % 26];
back[i] = int2alp[(alp2int[data[i]] >= size) ? alp2int[data[i]]-size : 26-(size-alp2int[data[i]])];
}
}
if (is_match(prev)) {
printf("%s", prev);
return true;
}
if (is_match(back)) {
printf("%s", back);
return true;
}
return false;
}
void init_alp2int() {
alp2int.insert(myMap::value_type('a', 0));
alp2int.insert(myMap::value_type('b', 1));
alp2int.insert(myMap::value_type('c', 2));
alp2int.insert(myMap::value_type('d', 3));
alp2int.insert(myMap::value_type('e', 4));
alp2int.insert(myMap::value_type('f', 5));
alp2int.insert(myMap::value_type('g', 6));
alp2int.insert(myMap::value_type('h', 7));
alp2int.insert(myMap::value_type('i', 8));
alp2int.insert(myMap::value_type('j', 9));
alp2int.insert(myMap::value_type('k', 10));
alp2int.insert(myMap::value_type('l', 11));
alp2int.insert(myMap::value_type('m', 12));
alp2int.insert(myMap::value_type('n', 13));
alp2int.insert(myMap::value_type('o', 14));
alp2int.insert(myMap::value_type('p', 15));
alp2int.insert(myMap::value_type('q', 16));
alp2int.insert(myMap::value_type('r', 17));
alp2int.insert(myMap::value_type('s', 18));
alp2int.insert(myMap::value_type('t', 19));
alp2int.insert(myMap::value_type('u', 20));
alp2int.insert(myMap::value_type('v', 21));
alp2int.insert(myMap::value_type('w', 22));
alp2int.insert(myMap::value_type('x', 23));
alp2int.insert(myMap::value_type('y', 24));
alp2int.insert(myMap::value_type('z', 25));
}
int main(int argc, char *argv[]) {
init_alp2int();
char rcv[100];
while(NULL != fgets(rcv, 80, stdin)) {
int length = get_length(rcv);
for (int i = 0; i < 26; i++) {
if (gen_caesar(rcv, i, length)) {
break;
}
}
}
return 0;
} | 1 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;
int main(){
long long int n,x,ans=0;
cin>>n>>x;
vector<long long int>a(10000000);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
if((a[i]+a[i+1])>x){
ans+=(a[i]+a[i+1]-x);
a[i+1]=a[i+1]-(a[i]+a[i+1]-x);
if(a[i+1]<0){
a[i]+=a[i+1];
a[i+1]=0;
}
}
}
cout<<ans<<endl;
return 0;
}
| #include <iostream>
using namespace std;
int main () {
int x, y;
cin >> x >> y;
int ans = 0;
ans += max(4 - x, 0);
ans += max(4 - y, 0);
if (x == 1 && y == 1) ans += 4;
ans *= 100000;
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int main(){
string s;
cin >> s;
map<char, int> mp;
rep(i, s.size()){
mp[s.at(i)]++;
}
ll ans = 1;
for(auto p : mp){
for(auto p2 : mp){
if(p2.first <= p.first) continue;
ans += (ll)p.second * p2.second;
}
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MAXN = 55556;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
string s;
cin >> s;
vector < vector < ll > > v(26, vector < ll > ());
ll n = s.length();
for(int i = 0; i < n; i++){
v[s[i] - 'a'].push_back(i);
}
ll ans = (n * (n - 1)) / 2;
for(int i = 0; i < n; i++){
ll idx = s[i] - 'a';
ans -= v[idx].end() - upper_bound(v[idx].begin(), v[idx].end(), i);
}
cout << ans + 1 << '\n';
}
| 1 |
#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;
}
| #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int n;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vll a(n);
rep(i, 0, n) cin >> a[i];
int k = a[0];
rep(i, 1, n) k = gcd(k, a[i]);
vii ans;
erep(x, 1, k) {
bool flag = true;
rep(i, 0, n) {
if (a[i] % x != 0) flag = false;
}
if (flag) {
ans.pb(x);
}
}
rep(i, 0, ans.size()) cout << ans[i] << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;
//cin.tie(0);ios::sync_with_stdio(false);
int main() {
int n;
string s;
cin >> n >> s;
ll ans;
map<char, ll> m;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') m['R']++;
if (s[i] == 'G') m['G']++;
if (s[i] == 'B') m['B']++;
}
ans = m['R'] * m['G'] * m['B'];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int k = j + j - i;
if (k < n) {
if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> r,g,b;
for(int i = 0; i < n; i++) {
char x;
cin >> x;
if(x=='R') r.push_back(i+1);
if(x=='G') g.push_back(i+1);
if(x=='B') b.push_back(i+1);
}
ll ans = r.size()*g.size()*b.size();
if(ans==0){
cout << 0 << endl;
return 0;
}
for(int i = 0; i < r.size(); i++) {
for(int j = 0; j < g.size(); j++) {
int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin();
if(y!=b.size()){
if(b[y]==g[j]+g[j]-r[i]) ans--;
}
y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin();
if(y!=b.size()){
if(b[y]==r[i]+r[i]-g[j]) ans--;
}
if((r[i]+g[j])%2==0){
y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin();
if(y!=b.size()){
if(b[y]==(r[i]+g[j])/2) ans--;
}
}
}
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int levenshtein_distance(string s1, string s2) {
vector<vector<int> > dp(s1.size() + 1, vector<int>(s2.size() + 1));
for(int i = 0; i <= s1.size(); i++) {
for(int j = 0; j <= s2.size(); j++) {
if(i == 0) dp[i][j] = j;
else if(j == 0) dp[i][j] = i;
else {
dp[i][j] = min({dp[i][j - 1] + 1, dp[i - 1][j] + 1, dp[i - 1][j - 1] + (s1[i - 1] != s2[j - 1])});
}
}
}
return dp[s1.size()][s2.size()];
}
string s, t;
int main() {
cin >> s >> t;
cout << levenshtein_distance(s, t) << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int ans=0;
if(a>b)
{
ans+=a;
a-=1;
}
else
{
ans+=b;
b-=1;
}
ans+=max(a,b);
cout<<ans;
}
| 0 |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
//#define __DEBUG__
class Dice {
private:
int iNS[4];
int iEW[4];
public:
Dice( int v1, int v2, int v3, int v4, int v5, int v6 ) {
iNS[0] = v1;
iNS[1] = v2;
iNS[2] = v6;
iNS[3] = v5;
iEW[0] = v1;
iEW[1] = v3;
iEW[2] = v6;
iEW[3] = v4;
#ifdef __DEBUG__
printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
}
void rotateN() {
int iTmp = iNS[0];
iNS[0] = iNS[1];
iNS[1] = iNS[2];
iNS[2] = iNS[3];
iNS[3] = iTmp;
iEW[0] = iNS[0];
iEW[2] = iNS[2];
#ifdef __DEBUG__
printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
}
void rotateS() {
int iTmp = iNS[0];
iNS[0] = iNS[3];
iNS[3] = iNS[2];
iNS[2] = iNS[1];
iNS[1] = iTmp;
iEW[0] = iNS[0];
iEW[2] = iNS[2];
#ifdef __DEBUG__
printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
}
void rotateE() {
int iTmp = iEW[0];
iEW[0] = iEW[3];
iEW[3] = iEW[2];
iEW[2] = iEW[1];
iEW[1] = iTmp;
iNS[0] = iEW[0];
iNS[2] = iEW[2];
#ifdef __DEBUG__
printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
}
void rotateW() {
int iTmp = iEW[0];
iEW[0] = iEW[1];
iEW[1] = iEW[2];
iEW[2] = iEW[3];
iEW[3] = iTmp;
iNS[0] = iEW[0];
iNS[2] = iEW[2];
#ifdef __DEBUG__
printf("NS[%d %d %d %d]\n", iNS[0], iNS[1], iNS[2], iNS[3]);
printf("EW[%d %d %d %d]\n", iEW[0], iEW[1], iEW[2], iEW[3]);
#endif
}
int getTop() {
return iNS[0];
}
};
int main(void) {
int v1, v2, v3, v4, v5, v6;
char cmd[128];
v1 = v2 = v3 = v4 = v5 = v6 = 0;
scanf("%d %d %d %d %d %d", &v1, &v2, &v3, &v4, &v5, &v6 );
scanf("%s", &cmd );
Dice *d = new Dice(v1, v2, v3, v4, v5, v6);
int iLen = strlen(cmd);
for (int i = 0; i < iLen; i++) {
char c = cmd[i] & 0xdf;
switch (c) {
case 'N':
d->rotateN();
break;
case 'S':
d->rotateS();
break;
case 'E':
d->rotateE();
break;
case 'W':
d->rotateW();
break;
default:
break;
}
}
printf("%d\n", d->getTop());
} | // -*- mode: C++ -*-
// Dice I
//
// Write a program to simulate rolling a dice, which can be constructed by the following net.
//
//
//
//
//
//
// As shown in the figures, each face is identified by a different label from 1 to 6.
//
// Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.
//
// Input
// In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.
//
// In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.
//
// Output
// Print the integer which appears on the top face after the simulation.
//
// Constraints
// 0≤ the integer assigned to a face ≤100
// 0≤ the length of the command ≤100
// Sample Input 1
// 1 2 4 8 16 32
// SE
// Sample Output 1
// 8
// You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E, you can see 8 on the top face.
//
//
//
// Sample Input 2
// 1 2 4 8 16 32
// EESWN
// Sample Output 2
// 32
#include <iostream>
#include <vector>
#include <string>
const unsigned int faces {6};
void E(std::vector<unsigned int>& dice);
void N(std::vector<unsigned int>& dice);
void S(std::vector<unsigned int>& dice);
void W(std::vector<unsigned int>& dice);
int main(int argc,
char* argv[])
{
std::vector<unsigned int> dice {};
dice.resize(faces, 0);
for(unsigned int i = 0; i < faces; i++){
std::cin >> dice[i];
}
std::string commands {};
std::cin >> commands;
for(unsigned int i = 0; i < commands.length(); i++){
switch(commands[i]){
case 'E':
E(dice);
break;
case 'N':
N(dice);
break;
case 'S':
S(dice);
break;
case 'W':
W(dice);
break;
default:
break;
}
}
std::cout << dice[0] << '\n';
return 0;
}
void E(std::vector<unsigned int>& dice)
{
unsigned int x = dice[0];
dice[0] = dice[3];
dice[3] = dice[5];
dice[5] = dice[2];
dice[2] = x;
}
void N(std::vector<unsigned int>& dice)
{
unsigned int x = dice[0];
dice[0] = dice[1];
dice[1] = dice[5];
dice[5] = dice[4];
dice[4] = x;
}
void S(std::vector<unsigned int>& dice)
{
unsigned int x = dice[0];
dice[0] = dice[4];
dice[4] = dice[5];
dice[5] = dice[1];
dice[1] = x;
}
void W(std::vector<unsigned int>& dice)
{
unsigned int x = dice[0];
dice[0] = dice[2];
dice[2] = dice[5];
dice[5] = dice[3];
dice[3] = x;
}
| 1 |
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main() {
string s;
cin >> s;
bool ok = false;
if (s == "hi") ok = true;
if (s == "hihi") ok = true;
if (s == "hihihi") ok = true;
if (s == "hihihihi") ok = true;
if (s == "hihihihihi") ok = true;
cout << (ok ? "Yes" : "No") << endl;
return 0;
} | #include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif
int main(){
string S;
cin >> S;
string ans = S.size()%2==0 ? "Yes" : "No";
for(int i=0; i<S.size(); i++){
if(S[i]!=(i%2==0?'h':'i')) ans = "No";
}
cout << ans << endl;
return 0;
}
| 1 |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
int n,m;
int a[105];
int main()
{
scanf("%d%d",&n,&m);
int odd1 = 0,odd2 = 0;
for (int i = 1;i <= m;i++)
{
scanf("%d",&a[i]);
if (a[i] & 1)
{
if (!odd1)
odd1 = i;
else if (!odd2)
odd2 = i;
else
{
puts("Impossible");
return 0;
}
}
}
if (odd1)
swap(a[odd1],a[1]);
if (odd2)
swap(a[odd2],a[m]);
for (int i = 1;i <= m;i++)
printf("%d ",a[i]);
printf("\n");
if (m == 1)
{
if (a[1] == 1)
{
puts("1");
printf("1\n");
}
else
{
puts("2");
printf("%d %d\n",a[1] - 1,1);
}
return 0;
}
printf("%d\n%d ",m - (a[m] == 1),a[1] + 1);
for (int i = 2;i < m;i++)
printf("%d ",a[i]);
if (a[m] > 1)
printf("%d",a[m] - 1);
printf("\n");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
typedef pair<int, int> P;
int N;
vector<int> A;
const int MONOID = 0;
ll f(ll x, ll y) {
return x + y;
}
void add(ll x, ll y) {
ll i = x + N - 1;
A.at(i) += y;
while (i > 0) {
i = (i-1)/2;
A.at(i) = f(A.at(i*2+1), A.at(i*2+2));
}
}
ll findRec(ll x, ll y, ll n, ll l, ll r) {
if (r <= x || y <= l) return MONOID;
if (x <= l && r <= y) return A.at(n);
return f(
findRec(x, y, n*2+1, l, (l+r)/2),
findRec(x, y, n*2+2, (l+r)/2, r)
);
}
ll find(ll x, ll y) {
return findRec(x, y+1, 0, 0, N);
}
int main() {
int n,q; cin >> n >> q;
N = 1;
while (N < n) N *= 2;
vector<int> C(n);
A.assign(3*n, 0);
loop(i,0,n) cin >> C[i];
vector<int> points[n+1];
vector<int> prev(n+1, -1);
loop(i,0,n) {
int c = C[i];
if (prev[c] != -1) {
points[prev[c]].emplace_back(i);
}
prev[c] = i;
}
vector<P> qs[n+1];
loop(i,0,q) {
int l,r;cin >> l >> r;
l--;r--;
qs[l].emplace_back(r, i);
}
vector<int> ans(q, 0);
for (int x=n-1; x>=0; x--) {
for (auto &&y: points[x]) {
add(y, 1);
}
for (auto q: qs[x]) {
ans[q.second] = q.first-x+1-find(0, q.first);
}
}
loop(i,0,q) cout << ans[i] << endl;
return 0;
}
| 0 |
#include<iostream>
#include<vector>
#include<queue>
#include<climits>
using namespace std;
typedef long long ll;
const ll INF = 2000000000000;
const int dmax = 2000000001;
int main(){
ll V,E,s,t,cost;
cin >> V >> E;
ll A[V][V];
for (int i=0;i<V;i++){
for (int j=0;j<V;j++){
A[i][j]=INF;
}
}
for (int i=0;i<E;i++){
cin >> s >> t >> cost;
A[s][t]=cost;
}
ll d[V][V][V];
for (int i=0;i<V;i++){
for (int j=0;j<V;j++){
if(i!=j){
d[i][j][0]=min(A[i][j],A[i][0]+A[0][j]);
}else{
d[i][j][0]=0;
}
}
}
for (int k=1;k<V;k++){
for (int i=0;i<V;i++){
for (int j=0;j<V;j++){
d[i][j][k]=min(d[i][j][k-1],d[i][k][k-1]+d[k][j][k-1]);
}
}
}
for (int i=0;i<V;i++){
for (int j=0;j<V;j++){
if(d[i][j][V-1]<0 && d[j][i][V-1]<0){
cout <<"NEGATIVE CYCLE" <<endl;
return 0;
}
}
}
for (int i=0;i<V;i++){
for (int j=0;j<V;j++){
if(d[i][j][V-1]>dmax){
cout << "INF";
}else{
cout << d[i][j][V-1];
}
if(j!=V-1){
cout << " ";
}
}
cout << endl;
}
return 0;
} | #include<iostream>
#include<cstdio>
#include<vector>
#include<cstdlib>
using namespace std;
int n,m;
int dis[16][16];
int dp[1<<16][16];
int subres[1<<16];
int sum;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
x--;y--;
dis[x][y]=dis[y][x]=z;
sum+=z;
}
for(int i=1;i<(1<<n);i++)
{
for(int j=0;j<n;j++)
{
if(i>>j&1)
{
for(int k=j+1;k<n;k++)
{
if(i>>k&1)subres[i]+=dis[j][k];
}
}
}
}
for(int i=0;i<(1<<n);i++)
{
for(int j=0;j<n;j++)dp[i][j]=-1;
}
for(int i=1;i+1<(1<<n);i++)
{
if(i>>(n-1)&1)continue;
if(i&1)
{
dp[i][0]=0;
for(int j=0;j<n;j++)
{
if(i>>j&1)
{
for(int k=j+1;k<n;k++)
{
if(i>>k&1)dp[i][0]+=dis[j][k];
}
}
}
}
}
for(int i=1;i+1<(1<<n);i++)
{
for(int j=0;j<n;j++)
{
if(dp[i][j]==-1)continue;
int st=((1<<n)-1)^i;
if(dis[j][n-1])
{
dp[(1<<n)-1][n-1]=max(dp[(1<<n)-1][n-1],dp[i][j]+subres[st]+dis[j][n-1]);
}
for(int k=(st-1)&st;k;k=(k-1)&st)
{
if(k>>(n-1)&1)continue;
for(int l=0;l<n;l++)
{
if(k>>l&1)
{
if(dis[j][l])
{
dp[i|k][l]=max(dp[i|k][l],dp[i][j]+subres[k]+dis[j][l]);
}
}
}
}
}
}
printf("%d",sum-dp[(1<<n)-1][n-1]);
return 0;
} | 0 |
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull unsigned long long
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
const int N = 2e5 + 123;
int main(){
speed;
int a, b, c, d;
cin >> a >> b >> c >> d;
for(int i = 1; i <= (d - b); ++i){
cout << 'U';
}
for(int i = 1; i <= (c - a); ++i){
cout << 'R';
}
for(int i = 1; i <= (d - b); ++i){
cout << 'D';
}
for(int i = 1; i <= (c - a); ++i){
cout << 'L';
}
cout << 'L';
for(int i = 1; i <= (d - b) + 1; ++i){
cout << 'U';
}
for(int i = 1; i <= (c - a) +1;++i){
cout << 'R';
}
cout << 'D';
cout << 'R';
for(int i = 1; i <= (d - b) + 1; ++i){
cout << 'D';
}
for(int i = 1; i <= (c - a) + 1; ++i){
cout << 'L';
}
cout << 'U';
} | /**
* auther: moririn_cocoa
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
#define ll long long
#define pll pair<ll,ll>
#define pq priority_queue
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
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;}
int main(int argc, const char * argv[]) {
int A;
int B;
int C;
int D;
cin >> A;
cin >> B;
cin >> C;
cin >> D;
cout << min ( A,B ) + min ( C,D ) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string A, B, S;
cin >> A >> B >> S;
cout << ((regex_match(S, regex("\\d{" + A + "}-\\d{" + B + "}"))) ? "Yes" : "No") << "\n";
} | #include<stdio.h>
#include<string.h>
int main(){
int a,b,total=0;
scanf("%d %d",&a,&b);
char s[a+b+2];
scanf("%s", &s);
for(int i=0; i<a+b+1 ;i++){
if(i!=a){
if(s[i]>=48 && s[i]<=57){
total++;
}
}
else {
if(s[i] == '-'){
total++;
}
}
}
if (total==a+b+1){
printf("Yes");
}
else {
printf("No");
}
return 0;
} | 1 |
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll
signed main(void)
{
int d;
while(cin >> d) {
ll sum = 0;
for(int i=d; i<=600-d; i+=d) {
sum += d*i*i;
}
cout << sum << endl;
}
return 0;
} | #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main(){
string str ;
while ( cin >> str ){
int len = str.size() ;
stack<char> container ;
for ( int i = 0 ; i < str.size() ; i ++ ){
if ( str[i] == 'T' ){
if ( !container.empty() ){
if ( container.top() == 'S' ){
len -= 2 ;
container.pop() ;
}
}else{
container.push(str[i]) ;
}
}else{
container.push(str[i]) ;
}
}
cout << len << endl ;
}
return 0 ;
} | 0 |
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair <int,ii>
#define iil pair<ll,ll>
#define iiil pair<ll,iil>
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define s(v) sort(v.begin(),v.end())
#define pf printf
#define sf scanf
#define MIN INT_MIN
#define MAX INT_MAX
#define Accepted 0
#define GCD(x,y) __gcd(x, y)
#define endl "\n"
using namespace std;
/**
const int maxn = 1e5 * 3;
int vis[maxn],l[maxn];
int indegree[maxn];
vector<int> graph[maxn];
vector<int> order;
vector<int> cst[maxn];
int gx[]= {2,2,-2,-2,1,-1,1,-1};
int gy[] ={1,-1,1,-1,2,2,-2,-2};
void DFS(int a,bool tpsort){
vis[a] = 1;
for(int i=0;i<graph[a].size();i++){
int r = graph[a][i];
if(vis[r]==0){
DFS(r,tpsort);
}
}
if(tpsort)order.push_back(a);
}
int vis[maxn],l2[maxn];
void BFS(int root){
memset(vis,0,sizeof(vis));
memset(l,0,sizeof(l));
vis[root] = 1;
l[root] = 0;
queue <int> q;
ans = 0;
mx = root;
q.push(root);
while(!q.empty()){
int cur = q.front();
q.pop();
int p = graph[cur].size();
for(int i=0;i<p;i++){
int r = graph[cur][i];
if(vis[r]==0){
vis[r] = 1 ;
l[r] = l[cur] + cst[cur][i];
if(l[r]>ans){
ans = l[r];
mx = r;
}
q.push(r);
}
}
}
// cout<< ans <<endl;
}
**/
int main(){
//fast
int n,val; cin >> n;
vector<int> v;
for(int i=0;i<2*n;i++){
cin>>val;
v.pb(val);
}
s(v);
int sum = 0;
for(int i=0;i<2*n;i+=2){
sum+=v[i];
}
cout << sum << endl;
return Accepted;
}
| #include<iostream>
using namespace std;
int main(){
int n,a=0,b=0,aa,bb;
cin>>n;
while(n!=0){
for(int i=0;i<n;i++){
cin>>aa>>bb;
if(aa<bb){
b+=aa+bb;
}else if(aa>bb){
a+=aa+bb;
}else if(aa==bb){
a+=aa;
b+=bb;
}
}
cout<<a<<" "<<b<<endl;
cin>>n;
a=0;
b=0;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 2;
const int INF = 2e18;
signed main() {
int N, M;
cin >> N >> M;
vector<vector<int>> G(N + 1);
vector<int> count(N + 1, 0);
int start = 0;
{
set<int> remain;
for (int i = 1; i <= N; i++) remain.insert(i);
for (int i = 0; i < N + M - 1; i++) {
int A, B;
cin >> A >> B;
G[A].push_back(B);
count[B]++;
remain.erase(B);
}
start = *remain.begin();
}
vector<int> ans(N + 1, -1), dis(N + 1, -1);
ans[start] = 0;
dis[start] = 0;
queue<int> explore;
explore.push(start);
while (!explore.empty()) {
int now = explore.front();
explore.pop();
for (int next : G[now]) {
count[next]--;
if (dis[next] < dis[now] + 1) {
dis[next] = dis[now] + 1;
ans[next] = now;
}
if (count[next] == 0) explore.push(next);
}
}
for (int i = 1; i <= N; i++) cout << ans[i] << endl;
}
| #include <bits/stdc++.h>
#include <atcoder/all>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
using namespace atcoder;
int main(){
int n,q;
std::cin >> n >> q;
fenwick_tree<ll> fw(n);
REP(i,n){
int input;
std::cin >> input;
fw.add(i,input);
}
REP(i,q){
int f,p,x;
std::cin >> f >> p >> x;
if(f==0){
fw.add(p,x);
}
else{
std::cout << fw.sum(p,x) << std::endl;
}
}
} | 0 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);
int main(){
{rep1(i,61) pw2[i]=2*pw2[i-1];}
{rep1(i,61) pw_2[i]=-2*pw_2[i-1];}
ll N; cin>>N;
if(N==0){
cout<<0<<endl;
return 0;
}
vector<ll> ans;
ll rem=N;
ll i=0;
while(rem!=0){
if(rem%pw2[i+1]!=0){
ans.pb(1);
rem-=pw_2[i];
}
else ans.pb(0);
i++;
}
rrep(i,sz(ans)) cout<<ans[i];
}
| #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
return A;
}
const int dm = 1400000;
char dn[dm], * di = dn;
const int MAX = 20000;
class unko {
public:
char C[MAX * 7 + 10], *K[MAX + 10];
constexpr unko() : C(), K() {
auto di = C + 3;
C[0] = '0';
C[0] = ' ';
C[0] = '\n';
K[0] = C;
K[1] = di;
rep1(i, MAX) {
int X = i;
int keta = 0;
char c[10] = {};
while (X) {
*(c + keta) = '0' + X % 10;
X /= 10;
keta++;
}
for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
*di++ = ' ';
*di++ = '\n';
K[i + 1] = di;
}
}
};
constexpr unko f;
inline void putint(int X) {
if (X > 20000) {
int ue = X / 10;
for (auto i = f.K[ue]; *i != ' '; i++) *di++ = *i;
*di++ = '0' + X % 10;
*di++ = ' ';
}
else for (auto i = f.K[X]; *i != '\n'; i++)* di++ = *i;
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int N = getint(), K = getint();
int A[200001];
rep(i, N) A[i] = getint();
ll owa = ll(N) * N;
rep(p, K) {
int B[200001] = {};
rep(i, N) {
B[max(0, i - A[i])]++;
B[min(N, i + A[i] + 1)]--;
}
ll kei = B[0];
A[0] = B[0];
rep1(i, N - 1) {
kei += (A[i] = A[i - 1] + B[i]);
}
if (kei == owa) break;
}
rep(i, N) putint(A[i]);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | 0 |
#include <bits/stdc++.h>
// #undef DEBUG // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
std::cerr << value << ", ";
debug(args...);
}
#define dbg(...) \
do { \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << " (L" << __LINE__ << ")" << endl; \
} while (0)
#else
#define dbg(...)
#endif
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
std::cin >> value;
read_from_cin(args...);
}
#define in(type, ...) \
type __VA_ARGS__; \
read_from_cin(__VA_ARGS__);
template <typename T>
void write_to_cout(const T& value) {
std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
std::cout << value << ' ';
write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using namespace std;
struct Construction {
ll s, t, x;
bool operator<(const Construction& c) const { return s < c.s; }
};
struct Person {
ll d, index;
bool operator<(const Person& p) const { return d < p.d; }
};
int main() {
in(ll, n, q);
vector<Construction> c(n);
rep(i, n) {
cin >> c[i].s >> c[i].t >> c[i].x;
c[i].s -= c[i].x;
c[i].t -= c[i].x;
}
sort(all(c));
vector<Person> p(q);
rep(i, q) {
cin >> p[i].d;
p[i].index = i;
}
sort(all(p));
multiset<ll> active;
priority_queue<pair<ll, ll>> que;
auto cit = c.begin();
vector<ll> ans(q);
for (const auto& pi : p) {
dbg(pi.d, pi.index);
while (cit != c.end() && cit->s <= pi.d) {
dbg(cit->s, cit->t, cit->x);
que.push({-cit->t, cit->x});
active.insert(cit->x);
++cit;
}
while (!que.empty() && -que.top().first <= pi.d) {
dbg(-que.top().first, que.top().second);
active.erase(active.find(que.top().second));
que.pop();
}
if (active.empty()) {
ans[pi.index] = -1;
} else {
ans[pi.index] = *active.begin();
}
}
rep(i, q) out(ans[i]);
}
| #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
const ll mod = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<vector<int> > stx(n, vector<int>(3));
for (auto &x: stx) cin >> x[0] >> x[1] >> x[2];
vector<int> d(q);
for (auto &x: d) cin >> x;
for (auto &x: stx) {
x[0] -= x[2];
x[1] -= x[2];
}
vector<int> time, pos;
priority_queue<Pii, vector<Pii>, greater<Pii> > pque;
priority_queue<int, vector<int>, greater<int> > watching;
unordered_set<int> roadblock;
for (auto &x: stx) {
pque.emplace(x[0], x[2]);
pque.emplace(x[1], x[2]);
}
int lastTime = -1000000007;
while (!pque.empty()) {
auto now = pque.top();
pque.pop();
if (now.first > lastTime) {
while (!watching.empty()) {
auto next = watching.top();
if (roadblock.find(next) == roadblock.end()) watching.pop();
else break;
}
if (watching.empty()) {
time.push_back(lastTime);
pos.push_back(-1);
}
else {
auto next = watching.top();
time.push_back(lastTime);
pos.push_back(next);
}
lastTime = now.first;
}
if (roadblock.find(now.second) == roadblock.end()) {
roadblock.insert(now.second);
watching.push(now.second);
}
else {
roadblock.erase(now.second);
}
}
time.push_back(lastTime);
pos.push_back(-1);
vector<int> ans(q);
for (int i = 0; i < q; i++) {
auto it = upper_bound(time.begin(), time.end(), d[i]);
int idx = distance(time.begin(), it) - 1;
ans[i] = pos[idx];
}
for (auto &x: ans) cout << x << endl;
return 0;
}
| 1 |
//#pragma GCC optimize("Ofast")
//#ifdef DEBUG
//#define _GLIBCXX_DEBUG
//#endif
// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined
// add_compile_options()
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <random>
using namespace std;
//using namesparsace __gnu_pbds;
void solve();
int main() {
srand(time(0));
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
solve();
return 0;
}
#define ld double
#define int long long
const int maxN = 3e3 + 10, maxK = 1e5 + 10, inf = 1e15 + 10, mod = 1e9 + 7, base = 223;
int n, a[16][16], cost[1 << 16], dp[1 << 16];
bool bit(int a, int i) {
return (a >> i) & 1;
}
int get(int mask) {
vector < int > v;
int res = 0;
for (int i = 0; i < n; i++) {
if (bit(mask, i)) {
for (int j = 0; j < v.size(); j++) {
res += a[v[j]][i];
}
v.push_back(i);
}
}
return res;
}
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i < (1 << n); i++) {
cost[i] = get(i);
}
for (int mask = 1; mask < (1 << n); mask++) {
int submask = mask;
while (submask > 0) {
dp[mask] = max(dp[mask], dp[mask ^ submask] + cost[submask]);
submask = mask & (submask - 1);
}
}
cout << dp[(1 << n) - 1];
}
// submask = mask & (mask - 1); | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#define MOD(x) (x + 1000000007) % (1000000007)
using namespace std;
template <class t>
using vec = vector<t>;
using ll = long long;
const int MAX = numeric_limits<int>::max();
template <class t>
ostream &operator<<(ostream &out, vec<t> &v)
{
for (auto &e : v)
out << e << " ";
out << "\n";
return out;
}
template <class t>
istream &operator>>(istream &in, vec<t> &v)
{
for (auto &e : v)
in >> e;
return in;
}
int n;
vec<vec<ll>> a;
vec<ll> dp, pre;
void find(ll used, vec<int> ¬_used, ll group_mask, int index)
{
if (index == not_used.size())
{
dp[used | group_mask] = max(dp[used | group_mask], dp[used] + pre[group_mask]);
return;
}
find(used, not_used, group_mask, index + 1);
find(used, not_used, group_mask | (1 << not_used[index]), index + 1);
}
int main()
{
cin >> n;
a = vec<vec<ll>>(n, vec<ll>(n));
cin >> a;
dp = vec<ll>(1 << n);
pre = vec<ll>(1 << n);
for (ll mask = 0; mask < (1 << n); mask++)
for (int i = 0; i < n; i++)
if (mask & (1 << i))
for (int j = i + 1; j < n; j++)
if (mask & (1 << j))
pre[mask] += a[i][j];
for (ll mask = 0; mask < (1 << n); mask++)
{
vec<int> not_used;
for (int i = 0; i < n; i++)
if (!(mask & (1 << i))) not_used.push_back(i);
find(mask, not_used, 0, 0);
}
cout << dp[(1 << n) - 1];
return 0;
} | 1 |
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,e;
cin>>a>>b>>c>>d;
if(a>b)
{
e=a;
a=b;
b=e;
}
if(c>d)
{
e=c;
c=d;
d=e;
}
cout<<(a+c);
return 0;
}
| #include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;
const int INF = numeric_limits<int>::max();
// (x, y) の最大公約数を返す関数
LL GCD(LL x, LL y) {
return y ? GCD(y, x%y) : x;
}
VPLL prime_factorize(LL n) {
VPLL res;
for (LL p=2; p*p<=n; p++) {
if (n%p!=0) continue;
int num = 0;
while (n%p==0) {num++; n/=p;}
res.push_back(make_pair(p,num));
}
if (n!=1) res.push_back(make_pair(n,1));
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
LL a, b;
cin >> a >> b;
long long G = GCD(a,b);
auto pf = prime_factorize(G);
cout << pf.size()+1 << endl;
return 0;
}
| 0 |
#include <cstdio>
#include <cstring>
#define ZeroMemory(ptr, size) ::memset(ptr, 0, size)
typedef struct
{
int id;
int cost;
int acquired;
} COMPETITION;
typedef struct
{
int cost;
} COMMITEE;
#define MAX_N 1000
int MaxAcquiredID(COMPETITION *lpCompes, int num)
{
int id = 0;
int max = 0;
for (int i = 0; i < num; i++)
{
if (max < lpCompes[i].acquired)
{
max = lpCompes[i].acquired;
id = lpCompes[i].id;
}
}
return(id);
}
int main()
{
COMPETITION compes[MAX_N];
COMMITEE commits[MAX_N];
int compesNum, commitsNum;
// Init
ZeroMemory(compes, sizeof(compes));
ZeroMemory(commits, sizeof(commits));
// Inputs
::scanf("%i %i", &compesNum, &commitsNum);
for (int i = 0; i < compesNum; i++)
{
compes[i].id = i + 1;
::scanf("%i", &compes[i].cost);
}
for (int i = 0; i < commitsNum; i++)
{
::scanf("%i", &commits[i].cost);
}
// Vote
for (int i = 0; i < commitsNum; i++)
{
for (int j = 0; j < compesNum; j++)
{
//::printf(">>%i, %i\n", compes[j].cost, commits[i].cost);
if (compes[j].cost <= commits[i].cost)
{
compes[j].acquired++;
break;
}
}
}
/*
for (int i = 0; i < compesNum; i++)
{
::printf(">%i\n", commits[i].cost);
}
*/
::printf("%i\n", ::MaxAcquiredID(compes, compesNum));
} | #include <stdio.h>
int main()
{
int n,m,b[1000],a[1000];
int sum[1000]={0};
scanf("%d %d",&n,&m);
for(int i=0;i<=n-1;i++){
scanf("%d",&a[i]);
}
for(int j=0;j<=m-1;j++){
scanf("%d",&b[j]);
}
for(int j=0;j<=m-1;j++){
for(int i=0;i<=n-1;i++){
if(b[j]>=a[i]) {sum[i]=sum[i]+1;break;}
}
}
int max=-1;
for(int k=0;k<=n-1;k++){
if(sum[k]>=max) max=sum[k];
}
for(int i=0;i<=n-1;i++){
if(sum[i]==max) printf("%d\n",i+1);
}
return 0;
} | 1 |
// #include<bits/stdc++.h>
// using namespace std;
// int main(){
// ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// int tc;
// cin >> tc;
// while(tc--){
// string s;
// cin >> s;
// int count_0 = 0, count_1 = 0;
// for(char ch : s)
// count_0 += 1 - ch + '0', count_1 += ch - '0';
// int ans = min(count_0, count_1);
// int c0 = 0, c1 = 0, n = s.size();
// for(int i = 0; i < n - 1; i++){
// c0 += 1 - s[i] + '0', c1 += s[i] - '0';
// ans = min(ans, c0 + count_1 - c1);
// ans = min(ans, c1 + count_0 - c0);
// }
// cout << ans << '\n';
// }
// }
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")
ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }
ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }
template<class T> ostream& operator<<(ostream& os,vector<T> V){
os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
return os<<"("<<P.first<<","<<P.second<<")";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif
#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}
struct compare{
bool operator() (const int &a,const int &b) const{
return a>b;
}
};
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
int n;
cin >> n;
vector<string> v(n);
for(int i = 0; i < n; i++)
cin >> v[i];
vector<pair<int, int> > balances, negative_balances;
for(int i = 0; i < n; i++){
int tot = 0, mn = 0;
for(auto j : v[i]){
if(j == '(')
tot++;
else tot--;
mn = min(mn, tot);
}
if(tot < 0)
negative_balances.push_back({tot - mn, -tot});
else
balances.push_back({-mn, tot});
}
sort(all(balances));
sort(all(negative_balances));
reverse(all(negative_balances));
int mn_neg_sum = 0, cur_neg_sum = 0;
for(auto i : negative_balances){
mn_neg_sum = max(mn_neg_sum, cur_neg_sum + i.first + i.second);
cur_neg_sum += i.second;
}
int mn_seen = 0;
for(auto i : balances)
if(i.first > mn_seen){
cout << "No" << endl;
return 0;
}
else mn_seen += i.second;
if(mn_seen != cur_neg_sum || mn_seen < mn_neg_sum){
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void fail(){
cout << "No" << endl;
exit(0);
}
int main(){
int N;
cin >> N;
vector<pair<int, int>> task_p, task_n;
for(int i=0; i<N; i++){
string S;
cin >> S;
int s = 0, mn = 0;
for(char c : S){
s += (c == '(' ? 1 : -1);
mn = min(mn, s);
}
int a = -mn, b = s;
(b >= 0 ? task_p : task_n).emplace_back(a, b);
}
sort(task_p.begin(), task_p.end());
int R = 0;
for(auto& p : task_p){
if(R < p.first) fail();
R += p.second;
}
sort(task_n.begin(), task_n.end(), [](auto a , auto b){ return a.first+a.second > b.first+b.second; });
for(auto& p : task_n){
if(R < p.first) fail();
R += p.second;
}
if(R) fail();
cout << "Yes" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;
int main(){
int g;
cin >>g;
int a,b;
cin >>a >>b;
if(g==1){cout << "Hello World" << endl;}else{cout << a+b << endl;}
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> II;
typedef vector< II > VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;
typedef vector<LL> VL;
typedef unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration
#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI 3.14159265358979323846264338327950288
#define DRT() int t; si(t); while(t--)
#define PlUSWRAP(index,n) index = (index+1)%n //index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n //index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5) //Round off d to nearest integer
#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
int main() {
// #ifndef ONLINE_JUDGE
// freopen("../input.txt", "r", stdin);
// freopen("../output.txt", "w", stdout);
// #endif
srand(chrono::steady_clock::now().time_since_epoch().count());
off;
LL n;
cin>>n;
if(n == 1){
cout<<"Hello World";
}
else{
LL a,b;
cin>>a>>b;
cout<<a+b;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ss = stringstream;
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
int n;
str s,t;
cin>>n>>s>>t;
int ans=2*n;
for(int i=n;i>0;i--)
{
bool c=true;
for(int j=0;j<i;j++)if(t[j]!=s[j+n-i]){c=false;break;}
if(c){ans=n+(n-i);break;}
}
cout<<ans<<"\n";
return 0;
}
| //using class
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
class Point{
public: //以下、外部からaccess可能
double x,y; //member
Point(double xx,double yy){ //コンストラクタ
x = xx;
y = yy;
}
};
double getDistance(Point p1, Point p2){
return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
}
int main(){
Point p1(0,0), p2(0,0); //変数宣言
//コンストラクタによって座標指定して初期化
cin >> p1.x >> p1.y >> p2.x >> p2.y; //public access可
printf ("%lf", getDistance(p1, p2) );
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define ls u*2
#define rs u*2+1
#define mid (l+r)/2
#define int long long
using namespace std;
const int N=3e5;
int n,m,s,t;
int x[N];
int bj[N*2],lmin[N*2],rmin[N*2];
inline int read(){
char c=getchar();
register int s=0;
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9'){
s=s*10+c-'0';
c=getchar();
}return s;
}
inline void pushdown(register int u){
if(!bj[u])return ;
bj[ls]+=bj[u];
bj[rs]+=bj[u];
lmin[ls]+=bj[u];
rmin[ls]+=bj[u];
lmin[rs]+=bj[u];
rmin[rs]+=bj[u];
bj[u]=0;
return ;
}
void update(int u){
lmin[u]=min(lmin[ls],lmin[rs]);
rmin[u]=min(rmin[ls],rmin[rs]);
}
int query(int u,int l,int r,int L,int R)
{
if(L>R)return 191919810889;
if(L<=l&&R>=r){
return lmin[u];
}
pushdown(u);
int minn=1919191989881;
if(L<=mid)minn=query(ls,l,mid,L,R);
if(R>mid)minn=min(minn,query(rs,mid+1,r,L,R));
update(u);
return minn;
}
int ask(int u,int l,int r,int L,int R)
{
if(L>R)return 191919818809;
if(L<=l&&R>=r){
return rmin[u];
}
pushdown(u);
int minn=1919191988819;
if(L<=mid)minn=ask(ls,l,mid,L,R);
if(R>mid)minn=min(minn,ask(rs,mid+1,r,L,R));
update(u);
return minn;
}
void add(int u,int l,int r,int k,int summ){
if(l==r){
lmin[u]=min(lmin[u],summ-l);
rmin[u]=min(rmin[u],summ+l);
// cout<<"hh:"<<rmin[u]<<endl;
return ;
}
pushdown(u);
if(k<=mid)add(ls,l,mid,k,summ);
if(k>mid)add(rs,mid+1,r,k,summ);
update(u);
}
int modify(int u,int l,int r){
if(l==r){
return rmin[u]-l;
}
pushdown(u);
int minn=191919818880;
minn=min(modify(ls,l,mid),modify(rs,mid+1,r));
return minn;
}
signed main()
{
n=read();m=read();s=read();t=read();
x[0]=s;
for(register int i=1;i<=m;i++){x[i]=read();}
memset(lmin,10,sizeof(lmin));
memset(rmin,10,sizeof(rmin));
add(1,1,n,t,0);
for(int i=1;i<=m;i++){
int af=min(query(1,1,n,1,x[i])+x[i],ask(1,1,n,x[i],n)-x[i]);
// cout<<af<<endl;
bj[1]+=abs(x[i]-x[i-1]);
lmin[1]+=abs(x[i]-x[i-1]);
rmin[1]+=abs(x[i]-x[i-1]);
add(1,1,n,x[i-1],af);
}
printf("%lld",modify(1,1,n));
return 0;
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 2e5 + 5 ;
const ll inf = 1e17 + 7 ;
using namespace std ;
int n, m, A, B, x[N] ;
ll bit[2][2][N], dist[N], f[2][N] ;
void put(int cx, int cy, int x, ll y) {
for ( ; x <= n ; x += x & (- x)) bit[cx][cy][x] = min(bit[cx][cy][x], y) ;
}
ll get(int cx, int cy, int x) {
ll res = inf ;
for ( ; x ; x -= x & (- x)) res = min(res, bit[cx][cy][x]) ;
return res ;
}
int main() {
scanf("%d%d%d%d", &n, &m, &A, &B) ;
rep(i, 1, m) scanf("%d", &x[i]) ;
rep(i, 0, 1) rep(j, 0, 1) rep(k, 1, n) bit[i][j][k] = inf ;
rep(i, 2, m) dist[i] = dist[i - 1] + abs(x[i] - x[i - 1]) ;
f[0][0] = abs(B - x[1]), f[1][0] = abs(A - x[1]) ;
put(0, 0, A, f[0][0] - dist[1] - A), put(0, 1, n - A + 1, f[0][0] - dist[1] + A) ;
put(1, 0, B, f[1][0] - dist[1] - B), put(1, 1, n - B + 1, f[1][0] - dist[1] + B) ;
rep(i, 1, m - 1) {
f[0][i] = min(get(1, 0, x[i + 1]) + dist[i] + x[i + 1], get(1, 1, n - x[i + 1] + 1) + dist[i] - x[i + 1]) ;
f[1][i] = min(get(0, 0, x[i + 1]) + dist[i] + x[i + 1], get(0, 1, n - x[i + 1] + 1) + dist[i] - x[i + 1]) ;
put(0, 0, x[i], f[0][i] - dist[i + 1] - x[i]), put(0, 1, n - x[i] + 1, f[0][i] - dist[i + 1] + x[i]) ;
put(1, 0, x[i], f[1][i] - dist[i + 1] - x[i]), put(1, 1, n - x[i] + 1, f[1][i] - dist[i + 1] + x[i]) ;
}
ll ans = inf ;
rep(i, 0, m - 1) ans = min(ans, min(f[0][i], f[1][i]) + dist[m] - dist[i + 1]) ;
printf("%lld\n", ans) ;
return 0 ;
} | 1 |
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
using namespace std;
#define mod 1000000007
// seiyaku[i][0] : 値iは行seiyaku[i][0]で最大値でないといけない
// seiyaku[i][1] : 値iは列seiyaku[i][0]で最大値でないといけない
int seiyaku[1000001][2] = {};
int main()
{
int n, m;
cin >> n >> m;
long long int ans = 1;
for(int i = 1; i <= n; i++){
int a;
cin >> a;
if(seiyaku[a][0] > 0) ans = 0;
else seiyaku[a][0] = i;
}
for(int i = 1; i <= m; i++){
int b;
cin >> b;
if(seiyaku[b][1] > 0) ans = 0;
else seiyaku[b][1] = i;
}
// i行目にはすでに最大値が埋められている
bool alreadymax_g[1001];
// i列目にはすでに最大値が埋められている
bool alreadymax_r[1001];
for(int i = 1; i <= n; i++){
alreadymax_g[i] = false;
}
for(int i = 1; i <= m; i++){
alreadymax_r[i] = false;
}
for(int i = n * m; i>= 1; i--){
int g = seiyaku[i][0];
int r = seiyaku[i][1];
if(g > 0 && r > 0){
// 行と列どちらにも制約がある(最大値となる)場合
// g行目r列目にiを埋めないといけない
if(alreadymax_g[g] || alreadymax_r[r]){
ans = 0;
} else {
alreadymax_g[g] = true;
alreadymax_r[r] = true;
}
} else if(g > 0 && r == 0){
// 行にのみ制約がある場合
// g行目に埋めることは確定しているが、列は確定していない
if(alreadymax_g[g]){
// g行目にすでに最大値が埋まっていたらアウト
ans = 0;
} else {
alreadymax_g[g] = true;
// g行目で制約を気にせず入れられるマスの数を求める
int tmp = 0;
for(int j = 1; j <= m; j++){
if(alreadymax_r[j]) tmp++;
}
ans = (ans * tmp) % mod;
}
} else if(g == 0 && r > 0){
// 列のみに制約がある場合
// 上と同様
if(alreadymax_r[r]){
ans = 0;
} else {
alreadymax_r[r] = true;
int tmp = 0;
for(int j = 1; j <= n; j++){
if(alreadymax_g[j]) tmp++;
}
ans = (ans * tmp) % mod;
}
} else {
// 行にも列にも制約がない場合
int tmp_g = 0;
int tmp_r = 0;
for(int j = 1; j <= n; j++){
if(alreadymax_g[j]) tmp_g++;
}
for(int j = 1; j <= m; j++){
if(alreadymax_r[j]) tmp_r++;
}
ans =(ans * (tmp_r * tmp_g - (n * m - i))) % mod;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
vector<int> ans;
for(int i = 0; i < 4; i++){
ans.resize(n);
ans[0] = i%2;
ans[1] = i/2;
for(int j = 1; j < n-1; j++){
if(s[j] == 'o'){
if(ans[j] == 0) ans[j+1] = ans[j-1];
else ans[j+1] = !ans[j-1];
}
else{
if(ans[j] == 0) ans[j+1] = !ans[j-1];
else ans[j+1] = ans[j-1];
}
}
if(s[0] == 'o'){
if((ans[0] == 0) ^ (ans[1] == ans.back())) continue;
}
else{
if((ans[0] == 0) ^ (ans[1] != ans.back())) continue;
}
if(s.back() == 'o'){
if((ans.back() == 0) ^ (ans[0] == ans[n-2])) continue;
}
else{
if((ans.back() == 0) ^ (ans[0] != ans[n-2])) continue;
}
for(int j = 0; j < n; j++){
cout << "SW"[ans[j]];
}
cout << endl;
return 0;
}
cout << -1 << endl;
return 0;
} | 0 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
const int MAX= 10000100;
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}
int main(void){
string str;
while(cin>>str){
vector<int> card;
vector<int> cnt(13,0);
for(int i = 0 ; i < str.size() ; i ++){
if('1' <= str[i] && str[1] <= '9'){
if('0' <= str[i + 1] && str[i + 1] <= '9'){
int num = 10 + str[i + 1] - '0';
card.push_back(num);
cnt[--num] ++;
i ++;
}else{
int num = str[i] - '0';
card.push_back(num);
cnt[--num] ++;
}
}
}
sort(card.begin(),card.end());
int ans[2][2] = {0,0,0,0};
int c1,c2;
c1 = c2 = 0;
bool straight = false;
rep(i,cnt.size()){
if(cnt[i] == 1 &&
cnt[i + 1] == 1 &&
cnt[i + 2] == 1 &&
cnt[i + 3] == 1 &&
cnt[i + 4] == 1){
straight = true;
break;
}
if(cnt[i] > 1 && c1 == 0)
c1 = cnt[i];
else if(cnt[i] > 1)
c2 = cnt[i];
}
if(straight)
cout<<"straight";
else if(c1 == 5)
cout<<"five card";
else if(c1 == 4 || c2 == 4)
cout<<"four card";
else if((c1 == 3 && c2 == 2) ||
(c1 == 2 && c2 == 3))
cout<<"full house";
else if(c1 == 3)
cout<<"three card";
else if(c1 == 2 && c2 == 2)
cout<<"two pair";
else if(c1 == 2)
cout<<"one pair";
else if(cnt[ 9] == 1 &&
cnt[10] == 1 &&
cnt[11] == 1 &&
cnt[12] == 1 &&
cnt[ 0] == 1)
cout<<"straight";
else
cout<<"null";
cout<<endl;
}
} | #include<iostream>
#include<stdio.h>
using namespace std;
int main() {
int c[5];
while (scanf("%d,%d,%d,%d,%d", &c[0], &c[1], &c[2], &c[3], &c[4]) != EOF) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j<4; j++) {
if (c[j] > c[j + 1]) {
int tmp = c[j];
c[j] = c[j + 1];
c[j + 1] = tmp;
}
}
}
if ((c[0]==c[1]&&c[1]==c[2]&&c[2]==c[3])||(c[1]==c[2]&&c[2]==c[3]&&c[3]==c[4]))cout << "four card" << endl;
else if ((c[0]==c[1]&&c[1]==c[2]&&c[3]==c[4])||(c[0]==c[1]&&c[2]==c[3]&&c[3]==c[4]))cout << "full house" << endl;
else if ((c[0]==1&&c[1]==10&&c[2]==11&&c[3]==12&&c[4]==13)||(c[0]+1==c[1]&&c[0]+2==c[2]&&c[0]+3==c[3]&&c[0]+4==c[4]))cout << "straight" << endl;
else if ((c[0]==c[1]&&c[1]==c[2])||(c[1]==c[2]&&c[2]==c[3])||(c[2]==c[3]&&c[3]==c[4]))cout << "three card" << endl;
else if ((c[0]==c[1]&&c[2]==c[3])||(c[1]==c[2]&&c[3]==c[4])||(c[0]==c[1]&&c[3]==c[4]))cout << "two pair" << endl;
else if ((c[0] == c[1]) || (c[1] == c[2]) || (c[2] == c[3]) || (c[3] == c[4]))cout << "one pair" << endl;
else cout << "null" << endl;
}
}
| 1 |
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
int fa[maxn],co[maxn];
bool bz[maxn],pd[maxn];
int i,j,k,l,r,t,n,m,cnt;
ll ans;
int getfa(int x){
if (!fa[x]) return x;
int t=getfa(fa[x]);
co[x]^=co[fa[x]];
return fa[x]=t;
}
int main(){
scanf("%d%d",&n,&m);
fo(i,1,m){
scanf("%d%d",&j,&k);
bz[j]=1;bz[k]=1;
l=getfa(j);r=getfa(k);
if (l<r){
swap(l,r);
swap(j,k);
}
if (l==r&&co[j]==co[k]) pd[l]=1;
if (l==r) continue;
pd[r]|=pd[l];
fa[l]=r;
co[l]=co[j]^co[k]^1;
}
fo(i,1,n)
if (!bz[i]) cnt++;
ans=(ll)cnt*(n-cnt)*2+(ll)cnt*cnt;
cnt=0;
fo(i,1,n)
if (bz[i]&&!fa[i]) cnt++;
ans+=(ll)cnt*cnt;
cnt=0;
fo(i,1,n)
if (bz[i]&&!fa[i]&&!pd[i]) cnt++;
fo(i,1,n)
if (bz[i]&&!fa[i]&&!pd[i]) ans+=(ll)cnt;
printf("%lld\n",ans);
} | #include <bits/stdc++.h>
using namespace std;
int col[100005];
vector<int> v[100005];
bool dfs(int node,int c)
{
if (col[node]!=-1)
return (col[node]==c);
col[node]=c;
bool ok=1;
for (int u:v[node])
ok&=dfs(u,!c);
return ok;
}
int main()
{
int n,m,c=0,b=0;
scanf("%d%d",&n,&m);
while (m--)
{
int a,b;
scanf("%d%d",&a,&b);
v[a].push_back(b);
v[b].push_back(a);
}
memset(col,-1,sizeof(col));
int nn=n;
long long ans=0;
for (int i=1;i<=n;i++)
{
if (v[i].empty())
{
ans+=2*nn-1;
nn--;
continue;
}
if (col[i]==-1)
{
c++;
b+=dfs(i,0);
}
}
printf("%lld",ans+1LL*c*c+1LL*b*b);
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
if (!target.empty()) {
std::string::size_type pos = 0;
while ((pos = s.find(target, pos)) != std::string::npos) {
s.replace(pos, target.length(), replacement);
pos += replacement.length();
}
}
return s;
}
const ll MOD = 998244353;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
struct UnionFind{
vector<ll> par,s,b,w;
UnionFind(ll N) : par(N),s(N),b(N),w(N){
REP(i,N){
par[i] = i;
b[i] = 0;
w[i] = 0;
s[i] = 0;
}
}
int root(int x){
if(par[x]==x){ return x; }
else{
par[x]= root(par[x]);
return par[x];
}
}
void unite(int x, int y){
int rx = root(x);
int ry = root(y);
if( rx!=ry ){
par[rx] = ry;
s[ry] += s[rx];
w[ry] += w[rx];
b[ry] += b[rx];
}
}
void coloring(int x,char c){
int rx = root(x);
if(c=='.'){
w[rx] += 1;
}else{
b[rx] += 1;
}
}
ll solve(int rx){
return w[rx]*b[rx];
}
};
int main(){
int H,W; cin>>H>>W;
string board[H]; CINA(board,H);
UnionFind uf(H*W);
REP(i,H){
REP(j,W){
uf.coloring(i*W+j,board[i][j]);
}
}
REP(i,H){
REP(j,W){
if(i+1<H){
if(board[i][j]!=board[i+1][j]){
uf.unite(i*W+j,(i+1)*W+j);
}
}
if(j+1<W){
if(board[i][j]!=board[i][j+1]){
uf.unite(i*W+j,i*W+j+1);
}
}
}
}
ll ans = 0;
map<int,int> mp;
REP(x,H*W){
int rx = uf.root(x);
if(mp[rx]==0){
++mp[rx];
ans += uf.solve(rx);
}
}
cout << ans << "\n";
} | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;
#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)
int main() {
int a, b;
cin >> a >> b;
cout << (a * b) << endl;
return 0;
} | 0 |
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double a;
double n;
double max,min,sum;
cin>>n;
sum=0;
max=-1000000;
min=1000000;
for( int i=0; i<n; i++ ) {
cin>>a;
sum+=a;
if( max < a ) {
max=a;
}
if( a < min ) {
min=a;
}
}
cout <<setprecision(12)<<min<<" "<<max<<" "<<sum<<endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
int n;
int a[10001];
int main(){
std::cin >> n;
rep(i, n)std::cin >> a[i];
std::cout << *std::min_element(a, a + n) << " " << *std::max_element(a, a + n) << " " << std::accumulate(a, a + n, 0ll) << std::endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
ll a[n];
rep(i, n) {
cin >> a[i];
}
string s;
cin >> s;
reverse(a, a + n);
reverse(ALL(s));
vector<ll> bs;
rep(i, n) {
for (auto b : bs) {
a[i] = min(a[i], a[i] ^ b);
}
if (s[i] == '0') {
if (a[i] != 0) bs.emplace_back(a[i]);
} else {
if (a[i]) {
cout << 1 << endl;
return;
}
}
}
cout << 0 << endl;
}
signed main() {
int tt;
cin >> tt;
while (tt--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif
namespace IO {
static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;
inline char myGetchar() {
static char buf[IN_BUF], *ps = buf, *pt = buf;
if (ps == pt) {
ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
}
return ps == pt ? EOF : *ps++;
}
template<typename T>
inline bool read(T &x) {
bool op = 0;
char ch = getchar();
x = 0;
for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
op ^= (ch == '-');
}
if (ch == EOF) {
return false;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + (ch ^ '0');
}
if (op) {
x = -x;
}
return true;
}
inline int readStr(char *s) {
int n = 0;
char ch = getchar();
for (; isspace(ch) && ch != EOF; ch = getchar())
;
for (; !isspace(ch) && ch != EOF; ch = getchar()) {
s[n++] = ch;
}
s[n] = '\0';
return n;
}
inline void myPutchar(char x) {
static char pbuf[OUT_BUF], *pp = pbuf;
struct _flusher {
~_flusher() {
fwrite(pbuf, 1, pp - pbuf, stdout);
}
};
static _flusher outputFlusher;
if (pp == pbuf + OUT_BUF) {
fwrite(pbuf, 1, OUT_BUF, stdout);
pp = pbuf;
}
*pp++ = x;
}
template<typename T>
inline void print_(T x) {
if (x == 0) {
putchar('0');
return;
}
static int num[40];
if (x < 0) {
putchar('-');
x = -x;
}
for (*num = 0; x; x /= 10) {
num[++*num] = x % 10;
}
while (*num){
putchar(num[*num] ^ '0');
--*num;
}
}
template<typename T>
inline void print(T x, char ch = '\n') {
print_(x);
putchar(ch);
}
inline void printStr_(const char *s, int n = -1) {
if (n == -1) {
n = strlen(s);
}
for (int i = 0; i < n; ++i) {
putchar(s[i]);
}
}
inline void printStr(const char *s, int n = -1, char ch = '\n') {
printStr_(s, n);
putchar(ch);
}
}
using namespace IO;
const int N = 205;
int n;
long long a[N];
char s[N];
long long B[64];
bool insert(long long x) {
for (int i = 59; ~i; --i) {
if (x >> i & 1) {
if (B[i]) {
x ^= B[i];
} else {
B[i] = x;
return true;
}
}
}
return false;
}
void solve() {
read(n);
for (int i = 1; i <= n; ++i) {
read(a[i]);
}
for (int i = 0; i < 60; ++i) {
B[i] = 0;
}
readStr(s + 1);
for (int i = n; i; --i) {
if (s[i] == '0') {
insert(a[i]);
} else {
if (insert(a[i])) {
print(1);
return;
}
}
}
print(0);
}
int main() {
int T = 1;
read(T);
while (T--) {
solve();
}
}
| 1 |
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n,a[5][N],i,j,k,x,y,b[N],c[2];
int main()
{
scanf("%d",&n);
for(i=1;i<=3;++i)
for(j=1;j<=n;++j)
scanf("%d",a[i]+j);
for(i=1;i<=n;++i)
{
x=y=a[1][i];
for(j=2;j<=3;++j)
x=max(x,a[j][i]),y=min(y,a[j][i]);
if(x-y!=2||y+1!=a[2][i])
{
printf("No");
return 0;
}
b[i]=x/3;
if(a[1][i]!=y)
c[i&1]=!c[i&1];
if((x/3-i)%2)
{
printf("No");
return 0;
}
}
for(i=1;i<=n;++i)
while(i!=b[i])
{
swap(b[i],b[b[i]]);
c[i&1^1]=!c[i&1^1];
}
if(c[0]||c[1])
printf("No");
else
printf("Yes");
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
using namespace std;
const int MOD=998244353;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n),d(n);
REP(i,n) cin >> d[i], c[d[i]]++;
if ( d[0]!=0 || c[0]>1 ) { cout << 0 << '\n'; return 0; }
int ans=1;
REP1(i,1,n-1) {
if ( c[i-1]==0 && c[i]==0 ) continue;
REP(j,c[i]) ans=(long long)ans*c[i-1]%MOD;
}
cout << ans << '\n';
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int c = 0;
for (char c1 : s) if (c1 == 'R') c++;
if (c != 2) cout << c << '\n';
else if (s[1] == 'S') cout << 1 << '\n';
else cout << '2' << '\n';
return 0;
} | #include <iostream>
using namespace std;
int main()
{
string S;
cin>>S;
char a=S[0]=='R';
char b=S[1]=='R';
char c=S[2]=='R';
if(a&b&c)
{
cout<<"3";
}
else if(a&b||b&c)
{
cout<<"2";
}
else if(a|b|c)
{
cout<<"1";
}
else
{
cout<<"0";
}
return 0;
}
| 1 |
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int main(){
int n,x,a;
while(~scanf("%d%d%d",&n,&x,&a)){
ll ans=0;
if(a>x)
ans+=a-x,a=x;
while(--n){
int b;
scanf("%d",&b);
if(a+b>x)
ans+=a+b-x,a=x-a;
else
a=b;
}
printf("%lld\n",ans);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll; //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint; //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll; //大きい順に取り出し
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数
void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------
//-----------------------------------------
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
std::chrono::system_clock::time_point start,end;
start = std::chrono::system_clock::now();
int n ;
ll x ;
cin >> n >> x ;
vll a(n+1,0) ;
REP(i,n){
cin >> a[i+1] ;
}
ll ans = 0 ;
FOR(i,1,n+1){
ll tmp = max((a[i]+a[i-1]-x),(ll)0) ;
ans += tmp ;
a[i] -= tmp ;
}
cout << ans <<endl;
end = std::chrono::system_clock::now();
auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
//std::cout << elapsed <<"ms"<< std::endl;
return 0;
}
| 1 |
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"
using namespace std;
const long long int MOD = 1000000007;
int N, M;
int main() {
ios::sync_with_stdio(false);
cin >> N >> M;
while (N) {
int num[1001];
int ans = 0;
set<int>F;
set<int>S;
for (int i = 0; i < N; i++)cin >> num[i];
F.insert(0);
for (int i = 0; i < N/2; i++) {
F.insert(num[i]);
for (int j = 0; j < N/2; j++) {
F.insert(num[i] + num[j]);
}
}
S.insert(0);
for (int i = N/2; i < N; i++) {
S.insert(num[i]);
for (int j = N/2; j < N; j++) {
S.insert(num[i] + num[j]);
}
}
set<int>::reverse_iterator ritr = S.rbegin();
for (auto i : F) {
if (ritr == S.rend())break;
while ((i + *ritr) > M) {
++ritr;
if (ritr ==S.rend())break;
}
if(ritr!=S.rend()) ans = max(ans, i + *ritr);
}
cout << ans << endl;
cin >> N >> M;
}
return 0;
} | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,a[2000];
vector<int> t;
int main(){
a[0]=0;
while(cin>>n>>m&&n&&m){
t.clear();
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=0;i<n;i++){
for(int j=i;j<=n;j++){
t.push_back(-(a[i]+a[j]));
}
}
sort(t.begin(),t.end());
int ans=0;
for(int i=0;i<(int)t.size();i++){
int x=-t[i];
int y=m-x;
if(y<0)continue;
vector<int> :: iterator it;
it = upper_bound(t.begin(),t.end(),-y);
if(it==t.end())continue;
int z = *it;
ans=max(ans,x-z);
}
cout<<ans<<endl;
}
return 0;
} | 1 |
//KING NIKAN
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
ll ans[60] ;
int main()
{
ios::sync_with_stdio(false) ;cin.tie(0) ;cout.tie(0) ;
ll k ;
cin >> k ;
cout << 50 << "\n" ;
ll x=k/50 ;
for(int i=0 ;i<50 ;i++)
{
ans[i] = x+49;
}
ll y = k%50;
for(int k=0 ;k<y ;k++)
{
for(int i=0 ;i<50 ;i++)
{
if(k==i)
{
ans[i]+=50 ;
}
else
{
ans[i]-=1 ;
}
}
}
for(int i=0 ;i<50 ;i++)
{
cout << ans[i] << " " ;
}
return 0 ;
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll>
#define m_p make_pair
#define V vector<ll>
#define U_MAP unordered_map<ll,ll>
ll n,cnt,ans[ohara],a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll cou[ohara];
//-------------------------↓↓↓↓↓↓------------------------
//------ 自分を天才だと信じる ------
int main(void){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>k;
rep(i,50)ans[i]=i;
rep(i,50){
ans[i]+=(k/50)*50;
cou[i]=k/50;
}
rep(i,k%50){
ans[i]+=50;
cou[i]++;
}
rep(i,50){
ans[i]-=(k-cou[i]);
}
Cout(50);
rep(i,50){
if(i==49)Cout(ans[i]);
else cout<<ans[i]<<" ";
}
return 0;
}
| 1 |
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cin >> str;
string str2;
int size = (int)str.size();
str2.resize(size);
for(int i =0; i<size;++i)
{
str2[size-1-i] = str[i];
}
cout << str2 << endl;
return(0);
} | #include <iostream>
#include <string>
#include <algorithm>
int main(void) {
std::string str;
std::cin >> str;
std::for_each(str.crbegin(), str.crend(), [](const char& ch){ std::cout << ch; });
std::cout << std::endl;
return 0;
} | 1 |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;
const int MAX=100000;
const int INFTY=1<<30;
int n,col[MAX],d[MAX];
vector<pair<int,int>> Q[MAX];//target,weight
void dijkstra(int s)
{
priority_queue<pair<int,int>> PQ;//weight,id
for(int i=0;i<n;i++)
{
d[i]=INFTY;
col[i]=0;
}
d[s]=0;
PQ.push(make_pair(0,s));
col[s]=1;
while(!PQ.empty())
{
pair<int,int> f=PQ.top();PQ.pop();
int u=f.second;
col[u]=2;
if(d[u]<f.first*(-1))continue;
for(int j=0;j<Q[u].size();j++)
{
int v=Q[u][j].first;
if(col[v]==2)continue;
if(d[u]+Q[u][j].second<d[v])
{
d[v]=d[u]+Q[u][j].second;
PQ.push(make_pair(d[v]*(-1),v));
col[v]=1;
}
}
}
for(int i=0;i<n;i++)
{
if(d[i]==INFTY)cout<<"INF"<<endl;
else cout<<d[i]<<endl;
}
return;
}
int main()
{
cin>>n;
int u;int m;cin>>m>>u;
int s,t,w;
for(int i=0;i<m;i++)
{
cin>>s>>t>>w;
Q[s].push_back(make_pair(t,w));
}
dijkstra(u);
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define eb emplace_back
typedef long long ll;
#define int ll
auto const inf = numeric_limits<int>::max()/4;
using Weight = int;
using Capacity = int;
struct Edge {
int src, dst; Weight weight;
Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
pair<vector<Weight>, bool> spfa(const Graph &g, int s){
const Weight inf = numeric_limits<Weight>::max()/4;
const int n = g.size(); priority_queue<int> q;
vector<Weight> dist(n, inf); vector<int> inQ(n);
vector<int> count(n);
dist[s] = 0; q.emplace(s); inQ[s] = true; ++count[s];
bool negCycle = false;
for(int i = 0; q.size(); i++){
int v = q.top(); q.pop(); inQ[v] = false;
for(auto &e : g[v]){
if(dist[v] != inf && dist[e.dst] > dist[v] + e.weight){
dist[e.dst] = dist[v] + e.weight;
if(!inQ[e.dst]){
q.emplace(e.dst); inQ[e.dst] = true; ++count[e.dst];
if(count[e.dst] >= n){ negCycle = true; goto END; }
}
}
}
}
END:;
return make_pair(dist, !negCycle);
}
signed main(){
int V,E,r;
while(cin >> V >> E >> r){
Graph g(V);
rep(i,E){
int a,b,c;
cin >> a >> b >> c;
g[a].eb(a,b,c);
}
bool ok;
vector<Weight> dist;
tie(dist, ok) = spfa(g,r);
if(ok){
for(int i = 0; i < (int)dist.size(); i++){
if(dist[i] == inf) cout << "INF";
else cout << dist[i];
cout << endl;
}
} else {
cout << "NEGATIVE CYCLE" << endl;
}
}
} | 1 |
#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 <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
while( cin >> n && n ){
int* table = new int[ (n+1) * (n+1) ]();
for( int i = 0; i < n; ++i ){
int sum_col = 0;
for( int j = 0; j < n; ++j ){
int d;
cin >> d;
table[ i * (n+1) + j ] = d;
table[ i * (n+1) + n ] += d;
table[ n * (n+1) + j ] += d;
table[ n * (n+1) + n ] += d;
}
}
for( int i = 0; i < n+1; ++i ){
for( int j = 0; j < n+1; ++j ){
cout.width( 5 );
cout << table[ i * (n+1) + j ];
}
cout << endl;
}
delete[] table;
}
return 0;
} | 1 |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
int i, j, n;
scanf("%d", &n);
for (i = 1; i <= n; i++){
if (i % 3 == 0){
printf(" %d", i);
}
else{
j = i;
while (j > 0){
if (j % 10 == 3){
printf(" %d", i);
break;
}
j /= 10;
}
}
}
putchar('\n');
return 0;
} | #include<iostream>
using namespace std;
int x, i = 1;
int n;
void check_num();
void include3();
void end_check_num();
void check_num() {
x = i;
if (x % 3 == 0){
cout << " " << i;
end_check_num();
}else include3();
}
void include3() {
if (x % 10 == 3){
cout << " " << i;
end_check_num();
}else{
x /= 10;
if (x)include3();
else end_check_num();
}
}
void end_check_num() {
if (++i <= n) check_num();
}
int main() {
cin >> n;
check_num();
cout << endl;
char c;
cin >> c;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int labs(long long int a, long long int b)
{
return ((a>b)?a-b:b-a);
}
long long int lmin(long long int a, long long int b)
{
return ((a>b)?b:a);
}
int main()
{
long long int n, k, x[100001];
cin >> n >> k;
for (int i = 0; i < n; ++i)
{
cin >> x[i];
}
long long int ans = 1145141919;
for (int i = k; i <= n; ++i)
{
ans = lmin(ans, labs(x[i-k]-x[i-1])+lmin(labs(x[i-k]),labs(x[i-1])));
}
cout << ans << endl;
return 0;
} | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
using namespace std;
long long N, K;
vector<long long> x;
long long calcTime(int i, int k){
if(k <= 1) return 0;
long long rt = (1L<<61), lt = (1L<<61);
int Rk = N - i - 1; //x[i]より右にある本数
int Lk = i; //x[i]より左にある本数
//右に行ってから左へ
for(int j = K - i - 1; j <= Rk; j++){
if(i + j >= N || j < 0) continue;
long long t = x[i + j] - x[i]; //右の端までの時間
t *= 2; //x[i]まで戻ってくる
t += x[i] - x[i - (K - j - 1)];//左の端まで
if(t < rt) rt = t;
}
//左に行ってから右へ
for(int j = K- N + i; j <= Lk; j++){
if(i < j || j < 0) continue;;
long long t = x[i] - x[i - j]; //左の端までの時間
t *= 2; //x[i]まで戻ってくる
t += x[i + (K - j - 1)] - x[i];//右の端まで
if(t < lt) lt = t;
}
return (long long) min(rt, lt);
}
int main(int argc, char* argv[]){
cin >> N >> K;
for(int i=1; i<=N; i++){
long long u;
cin >> u;
x.push_back(u);
}
//入力はソート済だが念のためソートする
sort(x.begin(), x.end());
long long ans = 0;
if(x[0] >= 0){
ans = (long long)abs(x[K-1]);
printf("%lld\n", ans);
return 0;
}
else if(x[N-1] <= 0){
ans = (long long)abs(x[N-K]);
printf("%lld\n", ans);
return 0;
}
int a, b;
for(int i=0; i<N; i++){
if(x[i] > 0){ break; }
a = i;
}
for(int i=N-1; i>=0; i--){
if(x[i] < 0){ break; }
b = i;
}
long long ans_a = abs(x[a]) + calcTime(a, K);
long long ans_b = abs(x[b]) + calcTime(b, K);
ans = min( ans_a, ans_b);
printf("%lld\n", ans);
return 0;
} | 1 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;
#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sz size()
#define eb emplace_back
int memo[64][64];
int main(void){
while(1){
int n,p;
int pl[64] = {0};
int ans = -1;
int bowl;
cin >> n >> p;
bowl = n;
if(n+p==0)break;
if(memo[n][p] == 0){
bowl = p;
rep(i,1000000){
if(bowl){
bowl--;
pl[(i%n)]++;
if(pl[i%n] == p){ans = i%n;break;}
}else{
bowl = pl[i%n];
pl[i%n] = 0;
}
}
cout << ans << endl;
memo[n][p] = ans;
}else{
cout << memo[n][p] << endl;
}
}
return 0;
} | #include <iostream>
using namespace std;
int main(){
int n,p;
while(1){
cin>>n>>p;
if(n==0&&p==0){
break;
}
int sum=p;
int cnt=0;
int *data;
int state=0;
data = new int[n];
for(int i=0;i<n;i++){
data[i]=0;
}
while(1){
if(sum==0){
sum+=data[cnt];
data[cnt]=0;
}
else{
data[cnt]++;
sum--;
if(sum==0){
int flag=0;
for(int i=0;i<n;i++){
if(i==cnt)continue;
else{
if(data[i]>0){
flag=1;
}
}
}
if(flag==0){
cout<<cnt<<endl;
state=2;
}
}
}
cnt++;
cnt%=n;
if(state==2)break;
}
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int D,G;
cin>>D>>G;
vector<pair<int,int>> vec(D);
for(int i=0;i<D;i++){
cin>>vec.at(i).first>>vec.at(i).second;
}
int ans=0;
for(int i=0;i<(1<<D);i++){
bitset<10> bit(i);
int point=0,ans_=0;
for(int j=0;j<D;j++){
if(bit.test(j)){
point+=100*(j+1)*vec.at(j).first+vec.at(j).second;
ans_+=vec.at(j).first;
}
}
int de=D;
while(point<G&&de>=1){
if(de*100<=G-point&&!bit.test(de-1)){
ans_+=min((G-point)/(de*100),vec.at(de-1).first-1);
point+=(min((G-point)/(de*100),vec.at(de-1).first-1))*(de*100);
}
de--;
}
if(point>=G&&ans==0){
ans=ans_;
}
if(point>=G&&ans_<ans) {
ans=ans_;
}
}
cout<<ans<<endl;
} | #include<cstdio>
#include<iostream>
using namespace std;
int h,w;
int l[200010],r[200010];
struct tree{
int l,r;
long long tag,v;
}tr[2][4*200010];
void build(int i,int l,int r)
{
tr[0][i].l=l,tr[0][i].r=r;
if (l==r) return;
int mid=(l+r)>>1;
build(i<<1,l,mid);
build(i<<1|1,mid+1,r);
}
void update(int i,int id)
{
tr[id][i].v=min(tr[id][i<<1].v,tr[id][i<<1|1].v);
}
void build2(int i,int l,int r)
{
tr[1][i].l=l,tr[1][i].r=r;
if (l==r) {tr[1][i].v=-l;return;}
int mid=(l+r)>>1;
build2(i<<1,l,mid);
build2(i<<1|1,mid+1,r);
update(i,1);
}
void add(int i,long long x,int id)
{
//if (id==0&&tr[id][i].l==2&&tr[id][i].l==tr[id][i].r)
// cout<<tr[id][i].v<<" "<<x<<" tree"<<endl;
tr[id][i].v+=x;
tr[id][i].tag+=x;
}
void pushdown(int i,int id)
{
if (tr[id][i].tag)
{
add(i<<1,tr[id][i].tag,id);
add(i<<1|1,tr[id][i].tag,id);
tr[id][i].tag=0;
}
}
void modify(int i,int l,int r,long long x,int id)
{
int L=tr[id][i].l,R=tr[id][i].r;
if (l>R) return;
if (l<=L&&R<=r)
{
add(i,x,id);
return;
}
pushdown(i,id);
int mid=(L+R)>>1;
if (l<=mid) modify(i<<1,l,r,x,id);
if (r>mid) modify(i<<1|1,l,r,x,id);
update(i,id);
}
long long query(int i,int l,int r,int id)
{
int L=tr[id][i].l,R=tr[id][i].r;
if (l>R) return 0;
//cout<<l<<" "<<r<<" "<<L<<" "<<R<<" "<<tr[id][i].v<<endl;
if (l<=L&&R<=r) return tr[id][i].v;
pushdown(i,id);
int mid=(L+R)>>1;
long long maxn=1e18;
if (l<=mid) maxn=min(maxn,query(i<<1,l,r,id));
if (r>mid) maxn=min(maxn,query(i<<1|1,l,r,id));
return maxn;
}
int main()
{
scanf("%d%d",&h,&w);
for (int i=1;i<=h;i++)
scanf("%d%d",&l[i],&r[i]);
build(1,1,w);build2(1,1,w);
for (int i=1;i<=h;i++)
{
long long other=min(0ll,r[i]+1+query(1,1,r[i],1)-query(1,r[i]+1,r[i]+1,0));
modify(1,r[i]+1,r[i]+1,other,0);
modify(1,r[i]+1,r[i]+1,other,1);
modify(1,l[i],r[i],1e9,0);
modify(1,l[i],r[i],1e9,1);
modify(1,1,w,1,0);
modify(1,1,w,1,1);
long long ans=query(1,1,w,0);
if (ans>=1e9) printf("-1\n");
else printf("%d\n",ans);
}
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.