結果

問題 No.351 市松スライドパズル
ユーザー startcppstartcpp
提出日時 2016-03-11 22:56:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,980 ms
コンパイル使用メモリ 54,660 KB
実行使用メモリ 9,512 KB
最終ジャッジ日時 2023-10-25 07:10:48
合計ジャッジ時間 4,477 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
9,512 KB
testcase_01 AC 2 ms
5,708 KB
testcase_02 AC 2 ms
5,708 KB
testcase_03 AC 2 ms
5,708 KB
testcase_04 AC 2 ms
5,708 KB
testcase_05 AC 2 ms
5,708 KB
testcase_06 AC 2 ms
5,708 KB
testcase_07 AC 2 ms
5,708 KB
testcase_08 AC 2 ms
5,708 KB
testcase_09 AC 2 ms
5,708 KB
testcase_10 AC 2 ms
5,708 KB
testcase_11 AC 2 ms
5,708 KB
testcase_12 AC 2 ms
5,708 KB
testcase_13 AC 138 ms
9,472 KB
testcase_14 AC 138 ms
9,484 KB
testcase_15 AC 141 ms
9,512 KB
testcase_16 AC 140 ms
9,512 KB
testcase_17 AC 140 ms
9,512 KB
testcase_18 AC 140 ms
9,512 KB
testcase_19 AC 142 ms
9,512 KB
testcase_20 AC 138 ms
9,512 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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