結果
| 問題 | No.3395 Range Flipping Game |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-12-03 10:12:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 806 bytes |
| コンパイル時間 | 342 ms |
| コンパイル使用メモリ | 41,800 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-03 10:12:07 |
| 合計ジャッジ時間 | 2,491 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d", &tn);
| ~~~~~^~~~~~~~~~~
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d%s", &n, s);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3395.cc: No.3395 Range Flipping Game - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 250000;
/* typedef */
/* global variables */
char s[MAX_N + 4];
/* subroutines */
inline void flip(char &c) { c = 'A' + 'B' - c; }
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n;
scanf("%d%s", &n, s);
for (int i = 0, f = 0; i < n; i++) {
if (i == 0) {
if (s[i] != 'A') flip(s[i]), f = 1;
}
else if (i == 1) {
if (s[i] != 'B') flip(s[i]), f = 1;
else if (f) break;
}
else {
if (s[i] != 'A') flip(s[i]), f = 1;
else if (f) break;
}
}
for (int i = 0; i < n && s[i] == 'A'; i++) flip(s[i]);
puts(s);
}
return 0;
}
tnakao0123