結果

問題 No.261 ぐるぐるぐるぐる!あみだくじ!
ユーザー Lepton_sLepton_s
提出日時 2015-08-01 00:19:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,041 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 78,864 KB
実行使用メモリ 15,700 KB
最終ジャッジ日時 2023-09-24 23:56:46
合計ジャッジ時間 10,791 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 24 ms
4,376 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 24 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 9 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 103 ms
4,780 KB
testcase_28 WA -
testcase_29 AC 25 ms
4,464 KB
testcase_30 AC 398 ms
7,660 KB
testcase_31 AC 192 ms
7,448 KB
testcase_32 AC 176 ms
7,572 KB
testcase_33 AC 116 ms
7,452 KB
testcase_34 AC 220 ms
7,452 KB
testcase_35 AC 76 ms
7,660 KB
testcase_36 AC 1,360 ms
13,652 KB
testcase_37 AC 2,658 ms
15,700 KB
testcase_38 AC 2,409 ms
15,700 KB
testcase_39 AC 644 ms
13,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;
#define T 12000000
#define R 33000
#define N 200

int n, m, r[N], s[N], s2[N], s3[N], t[R][N], a[N], tmp[N], rr[20], ccnt;

void ap(int *a, int *b){
	memcpy(tmp, a, sizeof(tmp));
	for(int i = 0; i < n; i++)
		a[i] = tmp[b[i]];
}

int lcm(int a, int b){
	return a/__gcd(a, b)*b;
}

int main(){
	srand(time(NULL));
	cin>>n>>m;
	int rnd1 = rand()%n, rnd2 = rand()%n;
	for(int i = 0; i < n; i++) r[i] = i;
	memcpy(s, r, sizeof(s));
	memcpy(s2, r, sizeof(s));
	memcpy(s3, r, sizeof(s));
	for(int i = 0; i < m; i++){
		int x, y;
		cin>>x>>y;
		swap(s[x-1], s[x]);
	}
	ll E = 1;
	for(int i = 0; i < n; i++){
		int cnt = 1, p = s[i];
		bool small = true;
		while(p!=i){
			if(p>i) small = false;
			p = s[p];
			cnt++;
		}
		if(small){
			rr[ccnt++] = i;
		}
		E = lcm(E, cnt);
	}
	ll F = sqrt(E)+2;
	for(int i = 0; i < F; i++){
		ap(s2, s);
		//for(int i = 0; i < n; i++) cout<<s2[i]<<" ";
		//cout<<endl;
	}
	for(int i = 0; i < F; i++){
		memcpy(t[i], s3, sizeof(s3));
		ap(s3, s2);
	}
//	for(int i = 0; i < n; i++) cout<<t[1][i]<<" ";
	//cout<<endl;
	int Q;
	cin>>Q;
	while(Q--){
		for(int i = 0; i < n; i++){
			cin>>a[i];
			a[i]--;
		}
		int res = -1;
		for(int i = 0; i < F; i++){
			for(int j = 0; j < F; j++){
				bool f = true;
				for(int k = 0; k < ccnt; k++){
					if(a[rr[k]]!=t[j][rr[k]]){
						f = false;
						break;
					}
				}
				if(f){
					//cerr<<i<<" "<<j<<" "<<F<<endl;
					res = (j*F-i+E-1)%E+1;
					i = j = F;
					break;
				}
			}
			ap(a, s);
		}
		cout<<res<<endl;
	}
	return 0;
}
0