結果

問題 No.2432 Flip and Move
ユーザー 沙耶花
提出日時 2023-08-18 22:53:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,570 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 4,109 ms
コンパイル使用メモリ 253,232 KB
最終ジャッジ日時 2025-02-16 10:34:48
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:16: warning: ‘D’ may be used uninitialized [-Wmaybe-uninitialized]
   50 |         K %= (D*2);
      |              ~~^~~
main.cpp:19:13: note: ‘D’ was declared here
   19 |         int D;
      |             ^

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	
	int h,w;
	cin>>h>>w;
	
	long long K;
	cin>>K;
	int D;
	{
		vector f(h,vector(w,vector<int>(4,0)));
		int cx = 0,cy = 0;
		int d = 0;
		vector<int> dx = {1,-1};
		rep(i,Inf32){
			
			f[cx][cy][d] ++;
			int nx = cx+dx[d&1];
			int ny = cy+dx[(d>>1)&1];
			if(nx<0||nx>=h){
				d ^= 1;
			}
			else{
				cx = nx;
			}
			if(ny<0||ny>=w){
				d ^= 2;
			}
			else{
				cy = ny;
			}
			if(cx==0&&cy==0&&d==0){
				D = i+1;
				break;
			}
		}
		
	}
	
	K %= (D*2);
	{
		vector f(h,vector(w,vector<int>(4,0)));
		int cx = 0,cy = 0;
		int d = 0;
		vector<int> dx = {1,-1};
		rep(i,K){
			
			f[cx][cy][d] ++;
			int nx = cx+dx[d&1];
			int ny = cy+dx[(d>>1)&1];
			if(nx<0||nx>=h){
				d ^= 1;
			}
			else{
				cx = nx;
			}
			if(ny<0||ny>=w){
				d ^= 2;
			}
			else{
				cy = ny;
			}
		}
		rep(i,h){
			rep(j,w){
				int cur =0;
				rep(k,4){
					cur ^= f[i][j][k];
				}
				cur %= 2;
				if(cur%2==1)cout<<'#';
				else cout<<'.';
			}
			cout<<endl;
		}
	}
	
	return 0;
}
0