結果
問題 | No.2432 Flip and Move |
ユーザー | momoyuu |
提出日時 | 2023-08-18 22:19:13 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,144 bytes |
コンパイル時間 | 2,703 ms |
コンパイル使用メモリ | 254,460 KB |
実行使用メモリ | 32,808 KB |
最終ジャッジ日時 | 2024-05-06 04:31:19 |
合計ジャッジ時間 | 6,890 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,752 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 77 ms
32,804 KB |
testcase_03 | AC | 88 ms
32,808 KB |
testcase_04 | AC | 14 ms
6,272 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; const int mx = 1e6; bool vis[4][mx+1]; int h,w; bool ans[mx+1]; inline int tok(int i,int j){ return i * w + j; } ll k; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>h>>w; cin>>k; int now = 0; int ni = 0; int nj = 0; int dx = 1; int dy = 1; stack<pair<int,pair<int,int>>> st; st.push(make_pair(0,make_pair(0,0))); vis[0][tok(0,0)] = 0; bool fn = false; while(true){ if(now==k) break; ans[tok(ni,nj)] ^= 1; int nni = ni + dx; if(nni<0||nni>=h){ nni = ni; dx *= -1; } int nnj = nj + dy; if(nnj<0||nnj>=w){ nnj = nj; dy *= -1; } ni = nni; nj = nnj; now++; if(fn) continue; int mask = 0; if(dx==-1) mask += 1; if(dy==-1) mask += 2; if(vis[mask][tok(nni,nnj)]==0){ vis[mask][tok(nni,nnj)] = 1; st.push(make_pair(mask,make_pair(nni,nnj))); continue; } vis[mask][tok(nni,nnj)] = 1; stack<pair<int,int>> nxt; ll cnt = 0; pair<int,pair<int,int>> want = make_pair(mask,make_pair(nni,nnj)); while(true){ if(st.top()==want){ cnt++; nxt.push(make_pair(nni,nnj)); break; } int nx = st.top().second.first; int ny = st.top().second.second; cnt++; nxt.push(make_pair(nx,ny)); st.pop(); continue; } fn = true; ll res = k - now; ll can = res / cnt; if(can%2==1){ while(nxt.size()){ int ni = nxt.top().first; int nj = nxt.top().second; ans[tok(ni,nj)] ^= 1; nxt.pop(); } } now += can * cnt; } for(int i = 0;i<h;i++){ for(int j = 0;j<w;j++){ if(ans[tok(i,j)]==0) cout<<'.'; else cout<<'#'; } cout<<'\n'; } }