結果
| 問題 |
No.429 CupShuffle
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2016-10-02 23:21:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 1,035 bytes |
| コンパイル時間 | 591 ms |
| コンパイル使用メモリ | 56,496 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 13:35:31 |
| 合計ジャッジ時間 | 1,362 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:14: warning: ‘w2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
48 | else if (r2[i] == w2) ans2 = i + 1;
| ^~
main.cpp:47:9: warning: ‘w1’ may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | if (r2[i] == w1) ans1 = i + 1;
| ^~
ソースコード
#include <iostream>
#include <string>
using namespace std;
const int MAX_N = 100010;
int c[MAX_N];
int r1[MAX_N], r2[MAX_N];
int main() {
int n, k, x;
cin >> n >> k >> x;
for (int i = 0; i < n; i++) {
r1[i] = i;
}
for (int i = 0; i < k; i++) {
string s1, s2;
cin >> s1 >> s2;
if (i == x - 1) {
for (int j = 0; j < n; j++) {
r2[j] = r1[j];
}
continue;
}
int a = stoi(s1),
b = stoi(s2);
swap(r1[a - 1], r1[b - 1]);
}
for (int i = 0; i < n; i++) {
cin >> c[i];
c[i]--;
}
int w1, w2;
for (int i = 0; i < n; i++) {
if (r1[i] != c[i]) {
w1 = r1[i];
w2 = c[i];
}
}
int ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++) {
if (r2[i] == w1) ans1 = i + 1;
else if (r2[i] == w2) ans2 = i + 1;
}
if (ans1 > ans2) swap(ans1, ans2);
cout << ans1 << " " << ans2 << endl;
return 0;
}
ふーらくたる