結果

問題 No.429 CupShuffle
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-10-02 22:39:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 72,888 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-08-13 17:08:41
合計ジャッジ時間 1,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 75 ms
4,648 KB
testcase_12 AC 68 ms
4,740 KB
testcase_13 AC 74 ms
4,712 KB
testcase_14 AC 75 ms
4,672 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:24: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  for (int i = k - 1; i > idx; --i){
                      ~~^~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;

int a[100010], b[100010];
int main(void){
	int n, k, x; cin >> n >> k >> x;
	int idx;
	rep(i, k){
		// printf("%d\n", i);
		string ta, tb; cin >> ta >> tb;
		if(ta == "?" && tb == "?"){
			idx = i;
			a[i] = 0, b[i] = 0;
		}else{
			a[i] = stoi(ta); b[i] = stoi(tb);
		}
	}
	vector<int> rv(n);
	rep(i, n){
		cin >> rv[i];
	}
	vector<int> v(n);
	rep(i, n){
		v[i] = i + 1;
	}

	//sei
	for (int i = 0; i < idx; ++i){
		swap(v[a[i] - 1], v[b[i] - 1]);
	}

	for (int i = k - 1; i > idx; --i){
		swap(rv[a[i] - 1], rv[b[i] - 1]);
	}

	vector<int> ans;
	rep(i, n){
		if(v[i] != rv[i]) ans.push_back(i);
	}
	rep(i, ans.size()){
		printf("%d ", ans[i] + 1);
	}
	printf("\n");
	return 0;
}
0