Submission #2107356


Source Code Expand

#include <queue>
#include <vector>
#include <iostream>
using namespace std;
const int inf = 1012345678;
int n, m, s, p[4009], b[4009], dist[4009], np[4009]; bool vis[4009];
int main() {
	cin >> n >> m; s = 2 * n + 1;
	for(int i = 0; i < s; i++) cin >> p[i], p[i]--, dist[i] = inf;
	for(int i = 0; i < m; i++) cin >> b[i], vis[b[i]] = true;
	queue<int> q1; q1.push(0); dist[0] = 0;
	while(!q1.empty()) {
		int u = q1.front(); q1.pop();
		for(int i = 0; i < m; i++) {
			if(dist[(u + b[i]) % s] == inf) {
				dist[(u + b[i]) % s] = dist[u] + 1;
				q1.push((u + b[i]) % s);
			}
		}
	}
	int ret = inf, sa = (s - p[0]) % s;
	for(int i = 0; i < 2 * s; i++) {
		bool flag = true;
		for(int j = 1; j < s; j++) {
			if((p[j] - p[0] + s) % s != j) flag = false;
		}
		if(flag) ret = min(ret, i + dist[sa]);
		vector<int> v;
		for(int j = 0; j < s; j++) {
			if(vis[j] && !vis[(j * 2) % s]) {
				v.push_back((j * 2) % s);
			}
		}
		for(int j = 0; j < s; j++) np[(j * 2) % s] = p[j];
		for(int j = 0; j < s; j++) p[j] = np[j];
		for(int j : v) vis[j] = true;
		vector<vector<int> > d(s);
		for(int j = 0; j < s; j++) {
			if(dist[j] != inf) {
				d[dist[j]].push_back(j);
			}
		}
		for(int j = 0; j < s - 1; j++) {
			for(int k : d[j]) {
				if(dist[k] != j) continue;
				for(int l : v) {
					int nxt = (k + l) % s;
					if(dist[nxt] > dist[k] + 1) {
						dist[nxt] = dist[k] + 1;
						d[dist[nxt]].push_back(nxt);
					}
				}
			}
		}
	}
	cout << (ret != inf ? ret : -1) << endl;
	return 0;
}

Submission Info

Submission Time
Task B - 天下一マジック
User square1001
Language C++14 (GCC 5.4.1)
Score 20
Code Size 1550 Byte
Status WA
Exec Time 1367 ms
Memory 608 KB

Judge Result

Set Name level1 level2 All
Score / Max Score 20 / 20 0 / 80 0 / 100
Status
AC × 16
AC × 19
WA × 17
AC × 33
WA × 42
Set Name Test Cases
level1 level1-00, level1-01, level1-02, level1-03, level1-04, level1-05, level1-06, level1-07, level1-08, level1-09, level1-10, level1-11, level1-12, level1-13, level1-14, level1-15
level2 level1-00, level1-01, level1-02, level1-03, level1-04, level1-05, level1-06, level1-07, level1-08, level1-09, level1-10, level1-11, level1-12, level1-13, level1-14, level1-15, level2-00, level2-01, level2-02, level2-03, level2-04, level2-05, level2-06, level2-07, level2-08, level2-09, level2-10, level2-11, level2-12, level2-13, level2-14, level2-15, level2-16, level2-17, level2-18, level2-19
All level1-00, level1-01, level1-02, level1-03, level1-04, level1-05, level1-06, level1-07, level1-08, level1-09, level1-10, level1-11, level1-12, level1-13, level1-14, level1-15, level2-00, level2-01, level2-02, level2-03, level2-04, level2-05, level2-06, level2-07, level2-08, level2-09, level2-10, level2-11, level2-12, level2-13, level2-14, level2-15, level2-16, level2-17, level2-18, level2-19, level3-00, level3-01, level3-02, level3-03, level3-04, level3-05, level3-06, level3-07, level3-08, level3-09, level3-10, level3-11, level3-12, level3-13, level3-14, level3-15, level3-16, level3-17, level3-18, level3-19, level3-20, level3-21, level3-22, level3-23, level3-24, level3-25, level3-26, level3-27, level3-28, level3-29, level3-30, level3-31, level3-32, level3-33, level3-34, level3-35, level3-36, level3-37, level3-38
Case Name Status Exec Time Memory
level1-00 AC 1 ms 256 KB
level1-01 AC 1 ms 256 KB
level1-02 AC 1 ms 256 KB
level1-03 AC 1 ms 256 KB
level1-04 AC 1 ms 256 KB
level1-05 AC 1 ms 256 KB
level1-06 AC 1 ms 256 KB
level1-07 AC 1 ms 256 KB
level1-08 AC 1 ms 256 KB
level1-09 AC 1 ms 256 KB
level1-10 AC 1 ms 256 KB
level1-11 AC 1 ms 256 KB
level1-12 AC 1 ms 256 KB
level1-13 AC 1 ms 256 KB
level1-14 AC 1 ms 256 KB
level1-15 AC 1 ms 256 KB
level2-00 AC 22 ms 256 KB
level2-01 AC 275 ms 384 KB
level2-02 AC 15 ms 256 KB
level2-03 WA 2 ms 384 KB
level2-04 WA 2 ms 384 KB
level2-05 WA 2 ms 384 KB
level2-06 WA 287 ms 384 KB
level2-07 WA 448 ms 384 KB
level2-08 WA 83 ms 384 KB
level2-09 WA 308 ms 512 KB
level2-10 WA 530 ms 552 KB
level2-11 WA 262 ms 384 KB
level2-12 WA 420 ms 384 KB
level2-13 WA 1367 ms 608 KB
level2-14 WA 542 ms 384 KB
level2-15 WA 3 ms 256 KB
level2-16 WA 732 ms 384 KB
level2-17 WA 264 ms 384 KB
level2-18 WA 27 ms 256 KB
level2-19 WA 147 ms 384 KB
level3-00 AC 1 ms 256 KB
level3-01 AC 27 ms 256 KB
level3-02 AC 151 ms 384 KB
level3-03 AC 645 ms 512 KB
level3-04 AC 29 ms 256 KB
level3-05 AC 371 ms 384 KB
level3-06 AC 63 ms 384 KB
level3-07 AC 129 ms 384 KB
level3-08 AC 416 ms 384 KB
level3-09 AC 131 ms 384 KB
level3-10 AC 88 ms 384 KB
level3-11 WA 2 ms 384 KB
level3-12 WA 3 ms 384 KB
level3-13 AC 4 ms 384 KB
level3-14 WA 56 ms 384 KB
level3-15 WA 207 ms 384 KB
level3-16 WA 22 ms 256 KB
level3-17 WA 80 ms 384 KB
level3-18 WA 164 ms 384 KB
level3-19 WA 247 ms 384 KB
level3-20 WA 408 ms 512 KB
level3-21 WA 6 ms 256 KB
level3-22 WA 2 ms 256 KB
level3-23 WA 294 ms 384 KB
level3-24 WA 503 ms 384 KB
level3-25 WA 46 ms 384 KB
level3-26 WA 221 ms 384 KB
level3-27 WA 478 ms 384 KB
level3-28 WA 83 ms 384 KB
level3-29 WA 490 ms 384 KB
level3-30 WA 56 ms 384 KB
level3-31 WA 3 ms 256 KB
level3-32 WA 5 ms 256 KB
level3-33 WA 376 ms 384 KB
level3-34 WA 448 ms 384 KB
level3-35 WA 468 ms 384 KB
level3-36 WA 434 ms 384 KB
level3-37 AC 1 ms 256 KB
level3-38 AC 405 ms 384 KB