//~ while (clock()<=69*CLOCKS_PER_SEC) //~ #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") //~ #pragma GCC optimize("Ofast") //~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //~ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; using pii=pair<int, int>; using pll=pair<ll, ll>; using vi=vector<int>; using vll=vector<ll>; template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; } #ifdef LOCAL #define _upgrade ios_base::sync_with_stdio(0); #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__); #else #define _upgrade ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define debug(...) 98; #define cerr if(0) cout #endif #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define erase_duplicates(x) sort(all(x)), (x).resize(distance((x).begin(), unique(all(x)))); #define watch(x) cout << (#x) << " is " << (x) << endl; #define pow2(x) ((x)*(x)) #define mod(x, m) ((((x) % (m)) + (m)) % (m)) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define REP(i, a, b) for(int i = a; i <= b; ++i) #define REPV(i, b, a) for(int i = b; i >= a; --i) #include "sonlib.h" const double m_pi = acos(-1.0); const int int_max = 0x3f3f3f3f; const int M7 = 1000*1000*1000+7; const int M9 = 1000*1000*1000+9; int N, S; vector<int> s1grup1; int s1tab[1000]; void robs111(){ int pos=1; s1grup1.pb(pos); s1tab[pos]=1; int br=0; for(int x=1;x<=N;++x){ for(int i=1;i<=N;++i){ int q=x+i; q%=N; ++q; if(s1tab[q]==1)continue; int pos2 = MoveProbe(q); pos2*=q; if(pos2!=0){ Examine(); pos=pos2; s1grup1.pb(pos); s1tab[pos]=1; br=1; break; } } if(br)break; MoveProbe(1); } int repos=-1; if(sz(s1grup1)==2){ repos=1; for(int i=1;i<=N;++i){ if(s1tab[i]==1)continue; MoveProbe(i); int pos2 = MoveProbe(repos); if(pos2==1){ swap(pos, repos); } else{ s1tab[i]=1; } } } int xxx = -1; for(int i=1;i<=N;++i){ if(s1tab[i]==0)xxx=i; } for(int i=1;i<=N;++i){ if(i == pos || i == repos)continue; if(s1tab[i]==0){ MoveProbe(i); Examine(); MoveProbe(pos); } else{ MoveProbe(xxx); MoveProbe(i); Examine(); MoveProbe(xxx); MoveProbe(pos); } } } vector<int> s2sciezki[1000]; vector<int> s2temp; int udane=3; int przejrz[1000]; queue<int> dop; void robs222(){ MoveProbe(2); s2temp.pb(2); Examine(); s2sciezki[2]=s2temp; MoveProbe(3); s2temp.pb(3); Examine(); s2sciezki[3]=s2temp; s2temp.clear(); MoveProbe(1); dop.push(1); dop.push(2); dop.push(3); przejrz[1]=1; przejrz[2]=1; przejrz[3]=1; while(!dop.empty()){ int cur = dop.front();//cout<<"cur: "<<cur<<endl; dop.pop(); if(sz(s2sciezki[cur])%2==1){ MoveProbe(2);//cout<<2<<endl; MoveProbe(3);//cout<<3<<endl; MoveProbe(1);//cout<<1<<endl; } for(int i=0;i<sz(s2sciezki[cur]);++i){ MoveProbe(s2sciezki[cur][i]);//cout<<s2sciezki[cur][i]<<endl; } s2temp = s2sciezki[cur]; for(int i=1;i<=N;++i){ if(przejrz[i]==1){ continue; } int x = MoveProbe(i);//cout<<i<<endl; if(x == 1){ przejrz[i]=1; Examine(); MoveProbe(cur);//cout<<cur<<endl; s2sciezki[i]=s2temp; s2sciezki[i].pb(i); dop.push(i); } } for(int i=sz(s2sciezki[cur])-2;i>=0;--i){ MoveProbe(s2sciezki[cur][i]);//cout<<s2sciezki[cur][i]<<endl; } if(sz(s2sciezki[cur])>0){ int y = MoveProbe(1);//cout<<1<<endl; if(y==1){ MoveProbe(2);//cout<<2<<endl; MoveProbe(3);//cout<<3<<endl; MoveProbe(1);//cout<<1<<endl; } } } } int s3tab[1000]; int s3moj[1000]; int s3mojm[1000]; int eg[1000]; void robs333(){ int pos =1; s3tab[pos]=1; eg[1]=1; int moves; while(1){ int pos =1; int olpos=1; int uda=0; moves+=800; if(rand()%3>0){ for(int i=1;i<=2*N;++i){ int q=i%N+1; if(q==pos)continue; int x = MoveProbe(q); if(s3moj[pos] == q && moves > 500000){ if(eg[pos]==0) Examine(); eg[pos]=1; } if(x==1){ s3moj[q]=q-1; if(s3moj[q]==0)s3moj[q]+=N; olpos=pos; pos=q; if(eg[pos]==0){ Examine(); } break; } } } else{ for(int i=2*N;i>=1;--i){ int q=i%N+1; if(q==pos || q==olpos)continue; int x = MoveProbe(q); if(s3mojm[pos] == q && moves > 500000){ if(eg[pos] == 0) Examine(); eg[pos]=1; } if(x==1){ s3mojm[q]=q+1; if(s3mojm[q]==N+1)s3mojm[q]-=N; olpos=pos; pos=q; if(eg[pos]==0){ Examine(); eg[pos]=1; } break; } } } } } int main(){ //_upgrade //cout<<fixed<<setprecision(15); //cout<<"!!!"; N = GetN(); S = GetSubtask(); //cout<<S<<endl; Examine(); if(N == 1)return 0; if(S == 1){ robs111(); } else if(S == 2){ robs222(); } else if(S == 3){ robs333(); } else{ MoveProbe(2); Examine(); MoveProbe(3); Examine(); MoveProbe(2); MoveProbe(4); Examine(); } return 0; } /* __builtin_popcount count total set bits on a given integer (use __builtin_popcountll for long long). */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | //~ while (clock()<=69*CLOCKS_PER_SEC) //~ #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") //~ #pragma GCC optimize("Ofast") //~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //~ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; using pii=pair<int, int>; using pll=pair<ll, ll>; using vi=vector<int>; using vll=vector<ll>; template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; } #ifdef LOCAL #define _upgrade ios_base::sync_with_stdio(0); #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__); #else #define _upgrade ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define debug(...) 98; #define cerr if(0) cout #endif #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define erase_duplicates(x) sort(all(x)), (x).resize(distance((x).begin(), unique(all(x)))); #define watch(x) cout << (#x) << " is " << (x) << endl; #define pow2(x) ((x)*(x)) #define mod(x, m) ((((x) % (m)) + (m)) % (m)) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define REP(i, a, b) for(int i = a; i <= b; ++i) #define REPV(i, b, a) for(int i = b; i >= a; --i) #include "sonlib.h" const double m_pi = acos(-1.0); const int int_max = 0x3f3f3f3f; const int M7 = 1000*1000*1000+7; const int M9 = 1000*1000*1000+9; int N, S; vector<int> s1grup1; int s1tab[1000]; void robs111(){ int pos=1; s1grup1.pb(pos); s1tab[pos]=1; int br=0; for(int x=1;x<=N;++x){ for(int i=1;i<=N;++i){ int q=x+i; q%=N; ++q; if(s1tab[q]==1)continue; int pos2 = MoveProbe(q); pos2*=q; if(pos2!=0){ Examine(); pos=pos2; s1grup1.pb(pos); s1tab[pos]=1; br=1; break; } } if(br)break; MoveProbe(1); } int repos=-1; if(sz(s1grup1)==2){ repos=1; for(int i=1;i<=N;++i){ if(s1tab[i]==1)continue; MoveProbe(i); int pos2 = MoveProbe(repos); if(pos2==1){ swap(pos, repos); } else{ s1tab[i]=1; } } } int xxx = -1; for(int i=1;i<=N;++i){ if(s1tab[i]==0)xxx=i; } for(int i=1;i<=N;++i){ if(i == pos || i == repos)continue; if(s1tab[i]==0){ MoveProbe(i); Examine(); MoveProbe(pos); } else{ MoveProbe(xxx); MoveProbe(i); Examine(); MoveProbe(xxx); MoveProbe(pos); } } } vector<int> s2sciezki[1000]; vector<int> s2temp; int udane=3; int przejrz[1000]; queue<int> dop; void robs222(){ MoveProbe(2); s2temp.pb(2); Examine(); s2sciezki[2]=s2temp; MoveProbe(3); s2temp.pb(3); Examine(); s2sciezki[3]=s2temp; s2temp.clear(); MoveProbe(1); dop.push(1); dop.push(2); dop.push(3); przejrz[1]=1; przejrz[2]=1; przejrz[3]=1; while(!dop.empty()){ int cur = dop.front();//cout<<"cur: "<<cur<<endl; dop.pop(); if(sz(s2sciezki[cur])%2==1){ MoveProbe(2);//cout<<2<<endl; MoveProbe(3);//cout<<3<<endl; MoveProbe(1);//cout<<1<<endl; } for(int i=0;i<sz(s2sciezki[cur]);++i){ MoveProbe(s2sciezki[cur][i]);//cout<<s2sciezki[cur][i]<<endl; } s2temp = s2sciezki[cur]; for(int i=1;i<=N;++i){ if(przejrz[i]==1){ continue; } int x = MoveProbe(i);//cout<<i<<endl; if(x == 1){ przejrz[i]=1; Examine(); MoveProbe(cur);//cout<<cur<<endl; s2sciezki[i]=s2temp; s2sciezki[i].pb(i); dop.push(i); } } for(int i=sz(s2sciezki[cur])-2;i>=0;--i){ MoveProbe(s2sciezki[cur][i]);//cout<<s2sciezki[cur][i]<<endl; } if(sz(s2sciezki[cur])>0){ int y = MoveProbe(1);//cout<<1<<endl; if(y==1){ MoveProbe(2);//cout<<2<<endl; MoveProbe(3);//cout<<3<<endl; MoveProbe(1);//cout<<1<<endl; } } } } int s3tab[1000]; int s3moj[1000]; int s3mojm[1000]; int eg[1000]; void robs333(){ int pos =1; s3tab[pos]=1; eg[1]=1; int moves; while(1){ int pos =1; int olpos=1; int uda=0; moves+=800; if(rand()%3>0){ for(int i=1;i<=2*N;++i){ int q=i%N+1; if(q==pos)continue; int x = MoveProbe(q); if(s3moj[pos] == q && moves > 500000){ if(eg[pos]==0) Examine(); eg[pos]=1; } if(x==1){ s3moj[q]=q-1; if(s3moj[q]==0)s3moj[q]+=N; olpos=pos; pos=q; if(eg[pos]==0){ Examine(); } break; } } } else{ for(int i=2*N;i>=1;--i){ int q=i%N+1; if(q==pos || q==olpos)continue; int x = MoveProbe(q); if(s3mojm[pos] == q && moves > 500000){ if(eg[pos] == 0) Examine(); eg[pos]=1; } if(x==1){ s3mojm[q]=q+1; if(s3mojm[q]==N+1)s3mojm[q]-=N; olpos=pos; pos=q; if(eg[pos]==0){ Examine(); eg[pos]=1; } break; } } } } } int main(){ //_upgrade //cout<<fixed<<setprecision(15); //cout<<"!!!"; N = GetN(); S = GetSubtask(); //cout<<S<<endl; Examine(); if(N == 1)return 0; if(S == 1){ robs111(); } else if(S == 2){ robs222(); } else if(S == 3){ robs333(); } else{ MoveProbe(2); Examine(); MoveProbe(3); Examine(); MoveProbe(2); MoveProbe(4); Examine(); } return 0; } /* __builtin_popcount count total set bits on a given integer (use __builtin_popcountll for long long). */ |