Submission #295511

# Submission time Handle Problem Language Result Execution time Memory
295511 2020-09-09T17:50:55 Z patrikpavic2 Space Pirate (JOI14_space_pirate) C++17
47 / 100
1190 ms 100164 KB
#include <cstdio>
#include <cstring>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;

const int N = 3e3 + 50;
const int LOG = 62;

int dis[N][N], udem[N], kor[N][N];
int bio[N], cnt[N], P[N], klsk, cik[N];

int n;
ll k;


void precompute(int x){
	memset(bio, 0, sizeof(bio));
	int cur = x, cdis = 0;
	while(!bio[cur]){
		kor[x][cdis] = cur;
		bio[cur] = 1;
		dis[x][cur] = cdis++;
		cur = P[cur]; 
	}
	udem[x] = cur;
	if(cur == x)
		cik[x] = cdis;
}

int main(){
	memset(dis, -1, sizeof(dis));
	scanf("%d%lld", &n, &k);
	for(int i = 1;i <= n;i++)
		scanf("%d", P + i);
	for(int i = 1;i <= n;i++)
		precompute(i);
	int koji_kl = (k - dis[1][udem[1]]) % cik[udem[1]];
	klsk = kor[udem[1]][koji_kl]; 
	for(int a = 1;a <= n;a++){
		for(int b = 1;b <= n;b++){
			if(dis[1][a] == -1){
				cnt[klsk]++;
				continue;
			}
			if(dis[b][a] != -1){
				int koji = (k - dis[1][a]) % (dis[b][a] + 1);
				if(koji == 0)
					cnt[a]++;
				else
					cnt[kor[b][koji - 1]]++;
			}
			else{
				int koji = (k - dis[1][a] - 1 - dis[b][udem[b]]) % cik[udem[b]];
				cnt[kor[udem[b]][koji]]++;
			}
		}
	}
	for(int i = 1;i <= n;i++)
		printf("%d\n", cnt[i]);	
}

Compilation message

space_pirate.cpp: In function 'int main()':
space_pirate.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |  scanf("%d%lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
space_pirate.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |   scanf("%d", P + i);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 37112 KB Output is correct
2 Correct 22 ms 37120 KB Output is correct
3 Correct 22 ms 37112 KB Output is correct
4 Correct 23 ms 37120 KB Output is correct
5 Correct 22 ms 37120 KB Output is correct
6 Correct 22 ms 37120 KB Output is correct
7 Correct 22 ms 37120 KB Output is correct
8 Correct 22 ms 37120 KB Output is correct
9 Correct 22 ms 37120 KB Output is correct
10 Correct 22 ms 37120 KB Output is correct
11 Correct 22 ms 37112 KB Output is correct
12 Correct 23 ms 37120 KB Output is correct
13 Correct 22 ms 37112 KB Output is correct
14 Correct 22 ms 37120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 37112 KB Output is correct
2 Correct 22 ms 37120 KB Output is correct
3 Correct 22 ms 37112 KB Output is correct
4 Correct 23 ms 37120 KB Output is correct
5 Correct 22 ms 37120 KB Output is correct
6 Correct 22 ms 37120 KB Output is correct
7 Correct 22 ms 37120 KB Output is correct
8 Correct 22 ms 37120 KB Output is correct
9 Correct 22 ms 37120 KB Output is correct
10 Correct 22 ms 37120 KB Output is correct
11 Correct 22 ms 37112 KB Output is correct
12 Correct 23 ms 37120 KB Output is correct
13 Correct 22 ms 37112 KB Output is correct
14 Correct 22 ms 37120 KB Output is correct
15 Correct 70 ms 49664 KB Output is correct
16 Correct 57 ms 48888 KB Output is correct
17 Correct 81 ms 49912 KB Output is correct
18 Correct 1190 ms 72568 KB Output is correct
19 Correct 681 ms 65656 KB Output is correct
20 Correct 586 ms 68092 KB Output is correct
21 Correct 943 ms 64808 KB Output is correct
22 Correct 383 ms 59256 KB Output is correct
23 Correct 756 ms 64236 KB Output is correct
24 Correct 361 ms 57720 KB Output is correct
25 Correct 58 ms 49408 KB Output is correct
26 Correct 1037 ms 72696 KB Output is correct
27 Correct 360 ms 55436 KB Output is correct
28 Correct 352 ms 60280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 144 ms 100164 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 37112 KB Output is correct
2 Correct 22 ms 37120 KB Output is correct
3 Correct 22 ms 37112 KB Output is correct
4 Correct 23 ms 37120 KB Output is correct
5 Correct 22 ms 37120 KB Output is correct
6 Correct 22 ms 37120 KB Output is correct
7 Correct 22 ms 37120 KB Output is correct
8 Correct 22 ms 37120 KB Output is correct
9 Correct 22 ms 37120 KB Output is correct
10 Correct 22 ms 37120 KB Output is correct
11 Correct 22 ms 37112 KB Output is correct
12 Correct 23 ms 37120 KB Output is correct
13 Correct 22 ms 37112 KB Output is correct
14 Correct 22 ms 37120 KB Output is correct
15 Correct 70 ms 49664 KB Output is correct
16 Correct 57 ms 48888 KB Output is correct
17 Correct 81 ms 49912 KB Output is correct
18 Correct 1190 ms 72568 KB Output is correct
19 Correct 681 ms 65656 KB Output is correct
20 Correct 586 ms 68092 KB Output is correct
21 Correct 943 ms 64808 KB Output is correct
22 Correct 383 ms 59256 KB Output is correct
23 Correct 756 ms 64236 KB Output is correct
24 Correct 361 ms 57720 KB Output is correct
25 Correct 58 ms 49408 KB Output is correct
26 Correct 1037 ms 72696 KB Output is correct
27 Correct 360 ms 55436 KB Output is correct
28 Correct 352 ms 60280 KB Output is correct
29 Runtime error 144 ms 100164 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -