結果

問題 No.2432 Flip and Move
ユーザー milanis48663220milanis48663220
提出日時 2023-08-18 23:28:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 671 ms / 2,000 ms
コード長 3,851 bytes
コンパイル時間 2,447 ms
コンパイル使用メモリ 142,324 KB
実行使用メモリ 280,180 KB
最終ジャッジ日時 2023-08-18 23:29:01
合計ジャッジ時間 15,737 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,448 KB
testcase_01 AC 2 ms
5,324 KB
testcase_02 AC 292 ms
280,180 KB
testcase_03 AC 455 ms
279,908 KB
testcase_04 AC 55 ms
106,032 KB
testcase_05 AC 56 ms
105,992 KB
testcase_06 AC 116 ms
118,276 KB
testcase_07 AC 269 ms
211,364 KB
testcase_08 AC 311 ms
221,184 KB
testcase_09 AC 387 ms
273,612 KB
testcase_10 AC 190 ms
207,336 KB
testcase_11 AC 209 ms
225,600 KB
testcase_12 AC 171 ms
189,832 KB
testcase_13 AC 161 ms
171,740 KB
testcase_14 AC 92 ms
68,516 KB
testcase_15 AC 329 ms
246,500 KB
testcase_16 AC 266 ms
124,160 KB
testcase_17 AC 625 ms
255,392 KB
testcase_18 AC 164 ms
73,500 KB
testcase_19 AC 453 ms
215,264 KB
testcase_20 AC 671 ms
271,652 KB
testcase_21 AC 452 ms
214,416 KB
testcase_22 AC 543 ms
235,868 KB
testcase_23 AC 121 ms
65,380 KB
testcase_24 AC 583 ms
249,824 KB
testcase_25 AC 421 ms
205,708 KB
testcase_26 AC 308 ms
177,784 KB
testcase_27 AC 24 ms
16,120 KB
testcase_28 AC 13 ms
11,516 KB
testcase_29 AC 473 ms
209,356 KB
testcase_30 AC 637 ms
261,536 KB
testcase_31 AC 297 ms
173,376 KB
testcase_32 AC 43 ms
23,028 KB
testcase_33 AC 612 ms
258,968 KB
testcase_34 AC 306 ms
136,284 KB
testcase_35 AC 202 ms
134,704 KB
testcase_36 AC 2 ms
5,388 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << 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; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using T = tuple<int, int, int>;
T nx[8000000];
ll seen[8000000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h, w; cin >> h >> w;
    ll k; cin >> k;
    auto to_idx = [&](int x, int y, int p){
        return (x*w+y)*8+p;
    };
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int p = 0; p < 8; p++){
                int dx = (p&1) ? -1 : 1;
                int dy = (p&2) ? -1 : 1;
                bool flip = (p&4) ? false : true;
                if(flip){
                    if(0 <= i+dx && i+dx < h){
                        nx[to_idx(i, j, p)] = T(i+dx, j, p^4);
                    }else{
                        nx[to_idx(i, j, p)] = T(i, j, p^4^1);
                    }
                }else{
                    if(0 <= j+dy && j+dy < w){
                        nx[to_idx(i, j, p)] = T(i, j+dy, p^4);
                    }else{
                        nx[to_idx(i, j, p)] = T(i, j, p^4^2);
                    }
                }
            }
        }
    }
    int x = 0, y = 0, p = 0;
    vector<T> path;
    for(ll idx = 0; idx < k*2; idx++){
        // cout << x << ' ' << y << ' ' << p << endl;
        if(seen[to_idx(x, y, p)] > 0){
            T t(x, y, p);
            ll head = 0;
            ll cycle = 0;
            for(int i = 0; i < path.size(); i++){
                if(t == path[i]){
                    head = i;
                    cycle = path.size()-head;
                    break;
                }
            }
            ll cnt_cycle = (k*2-head)/cycle;
            ll rem = (k*2-head)%cycle;
            vector<T> v_cycle;
            for(int i = head; i < path.size(); i++){
                v_cycle.push_back(path[i]);
            }
            for(int i = 0; i < cycle; i++){
                auto [xx, yy, pp] = v_cycle[i];
                seen[to_idx(xx, yy, pp)] += cnt_cycle-1;
                if(i < rem){
                    seen[to_idx(xx, yy, pp)]++;
                }
            }
            break;
        }
        path.push_back({x, y, p});
        seen[to_idx(x, y, p)]++;
        auto [xx, yy, pp] = nx[to_idx(x, y, p)];
        x = xx;
        y = yy;
        p = pp;
        assert(idx < 10*h*w);
    }
    auto ans = vec2d(h, w, 0);
    for(int x = 0; x < h; x++){
        string s;
        for(int y = 0; y < w; y++){
            for(int p = 0; p < 4; p++){
                ans[x][y] ^= (seen[to_idx(x, y, p)]%2);
            }
            s += (ans[x][y] == 0 ? '.' : '#');
        }
        cout << s << '\n';
    }
}
0