QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#771073#7866. TeleportationgzyWA 4ms17372kbC++141.3kb2024-11-22 09:33:262024-11-22 09:33:26

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 09:33:26]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:17372kb
  • [2024-11-22 09:33:26]
  • 提交

answer

#include<bits/stdc++.h>
#define pb emplace_back
#define pi pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
using ll = long long;
using db = double;

constexpr int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
#define gc() getchar()//(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? EOF : *p1++)

int rd() {int x = 0, f = 1;char c = gc();while (!isdigit(c)) {if (c == '-') f = -1;c = gc();}while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc();return x * f;}

const int N = 2e5 + 7;
int i, j, k, n, m;
int f[N], a[N], v[N], u[N];
set<int> d[N];
queue<int> q, t;

int dis(int x, int y) {return y - x + (x > y) * n;}

signed main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
//	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	n = rd(), k = rd();
	for(i = 0; i < n; i++) v[i] = (a[i] = rd()) + i;
	for(i = 0; i < n; i++) if(i != k) d[v[i]].insert(i);
	q.push(k), t.push(k);
	while(q.size()) {
		k = q.front(), q.pop();
		i = t.front(), t.pop();
		while(!d[i].size()) {
			i = (i - 1 + n) % n;
			if(u[i]) break;
		}
		if(u[i]) continue;
		u[k] = 1;
		for(int x : d[i]) {
			f[x] = f[k] + dis(i, k) + 1;
			if(a[x]) q.push(x), t.push(x);
		}
		q.push(k), t.push(i);
		d[i].clear();
	}
	printf("%d\n", f[0]);
	return 0;
}



详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 16164kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 3ms
memory: 17372kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 17120kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 4ms
memory: 15944kb

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 3ms
memory: 16848kb

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 15964kb

input:

300 25
182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...

output:

23

result:

wrong answer 1st numbers differ - expected: '10', found: '23'