結果

問題 No.351 市松スライドパズル
ユーザー startcpp
提出日時 2016-03-11 22:56:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 55,644 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2024-09-25 02:30:54
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%d%d%d", &h, &w, &n);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |                 scanf("%s%d", s[i], &val[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

//1マスに注目し、k回目に左上あったマスはk-1回目にどこにあったか?を考えるとO(N)で解ける。
#include <cstdio>
#include <iostream>
using namespace std;

int h, w;
int n;
char s[1000000][2]; int val[1000000];

int main(){
	int i;
	int r = 0, c = 0;
	
	scanf("%d%d%d", &h, &w, &n);
	for( i = 0; i < n; i++ ){
		scanf("%s%d", s[i], &val[i]);
	}
	
	for( i = n - 1; i >= 0; i-- ){
		if(s[i][0] == 'R'){	//列が動くので注意
			c = (c + w - (val[i] == r)) % w;
		}
		else{
			r = (r + h - (val[i] == c)) % h;
		}
	}
	if( (r + c) % 2 ){ cout << "black" << endl; }
	else{ cout << "white" << endl; }
	return 0;
}
0