結果

問題 No.2432 Flip and Move
ユーザー milanis48663220milanis48663220
提出日時 2023-08-18 23:13:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,543 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 140,088 KB
実行使用メモリ 434,376 KB
最終ジャッジ日時 2023-08-18 23:14:03
合計ジャッジ時間 37,918 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,388 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 599 ms
434,376 KB
testcase_03 AC 1,762 ms
421,224 KB
testcase_04 AC 301 ms
241,384 KB
testcase_05 AC 320 ms
241,388 KB
testcase_06 AC 253 ms
175,996 KB
testcase_07 AC 1,102 ms
301,392 KB
testcase_08 AC 1,242 ms
321,496 KB
testcase_09 AC 1,674 ms
409,880 KB
testcase_10 AC 392 ms
277,212 KB
testcase_11 AC 467 ms
315,796 KB
testcase_12 AC 357 ms
235,372 KB
testcase_13 AC 352 ms
243,840 KB
testcase_14 AC 401 ms
100,460 KB
testcase_15 AC 1,451 ms
362,132 KB
testcase_16 AC 791 ms
153,984 KB
testcase_17 AC 1,978 ms
321,756 KB
testcase_18 AC 388 ms
91,504 KB
testcase_19 AC 1,688 ms
265,684 KB
testcase_20 TLE -
testcase_21 AC 1,539 ms
261,864 KB
testcase_22 AC 1,393 ms
302,916 KB
testcase_23 AC 257 ms
77,520 KB
testcase_24 AC 1,924 ms
312,396 KB
testcase_25 AC 1,377 ms
248,612 KB
testcase_26 AC 969 ms
236,260 KB
testcase_27 AC 30 ms
19,488 KB
testcase_28 AC 13 ms
10,808 KB
testcase_29 AC 1,402 ms
258,284 KB
testcase_30 TLE -
testcase_31 AC 949 ms
227,376 KB
testcase_32 AC 58 ms
26,044 KB
testcase_33 TLE -
testcase_34 AC 963 ms
170,044 KB
testcase_35 AC 582 ms
179,088 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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>;

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 nx = vec3d(h, w, 8, T(0, 0, 0));
    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[i][j][p] = T(i+dx, j, p^4);
                    }else{
                        nx[i][j][p] = T(i, j, p^4^1);
                    }
                }else{
                    if(0 <= j+dy && j+dy < w){
                        nx[i][j][p] = T(i, j+dy, p^4);
                    }else{
                        nx[i][j][p] = T(i, j, p^4^2);
                    }
                }
            }
        }
    }
    auto seen = vec3d(h, w, 8, 0ll);
    int x = 0, y = 0, p = 0;
    vector<T> path;
    for(ll idx = 0; idx < k*2; idx++){
        if(seen[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[xx][yy][pp] += cnt_cycle-1;
                if(i < rem){
                    seen[xx][yy][pp]++;
                }
            }
            break;
        }
        path.push_back({x, y, p});
        seen[x][y][p]++;
        auto [xx, yy, pp] = nx[x][y][p];
        x = xx;
        y = yy;
        p = pp;
    }
    auto ans = vec2d(h, w, 0);
    for(int x = 0; x < h; x++){
        for(int y = 0; y < w; y++){
            for(int p = 0; p < 4; p++){
                ans[x][y] ^= (seen[x][y][p]%2);
            }
            cout << (ans[x][y] == 0 ? '.' : '#');
        }
        cout << endl;
    }
}
0