結果

問題 No.2432 Flip and Move
ユーザー momoyuumomoyuu
提出日時 2023-08-18 22:19:27
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,143 bytes
コンパイル時間 3,238 ms
コンパイル使用メモリ 253,192 KB
実行使用メモリ 32,900 KB
最終ジャッジ日時 2023-08-18 22:19:36
合計ジャッジ時間 7,443 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 77 ms
32,748 KB
testcase_03 AC 88 ms
32,900 KB
testcase_04 AC 13 ms
6,388 KB
testcase_05 AC 13 ms
6,392 KB
testcase_06 AC 25 ms
12,292 KB
testcase_07 AC 61 ms
22,160 KB
testcase_08 AC 65 ms
24,152 KB
testcase_09 AC 91 ms
31,720 KB
testcase_10 AC 53 ms
21,688 KB
testcase_11 AC 70 ms
24,764 KB
testcase_12 AC 43 ms
19,044 KB
testcase_13 AC 39 ms
15,752 KB
testcase_14 AC 19 ms
9,928 KB
testcase_15 AC 83 ms
27,300 KB
testcase_16 AC 38 ms
15,096 KB
testcase_17 AC 73 ms
28,796 KB
testcase_18 AC 20 ms
10,456 KB
testcase_19 AC 57 ms
23,048 KB
testcase_20 AC 78 ms
31,568 KB
testcase_21 AC 66 ms
22,612 KB
testcase_22 AC 75 ms
25,496 KB
testcase_23 AC 18 ms
9,088 KB
testcase_24 AC 70 ms
27,672 KB
testcase_25 AC 51 ms
21,208 KB
testcase_26 AC 37 ms
16,204 KB
testcase_27 AC 4 ms
4,384 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 65 ms
21,964 KB
testcase_30 AC 90 ms
29,848 KB
testcase_31 AC 41 ms
15,844 KB
testcase_32 AC 7 ms
5,376 KB
testcase_33 AC 92 ms
29,288 KB
testcase_34 AC 43 ms
16,656 KB
testcase_35 AC 29 ms
11,764 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    ll 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';
    }
}

0