Submission #289371

# Submission time Handle Problem Language Result Execution time Memory
289371 2020-09-02T15:39:57 Z limabeans Space Pirate (JOI14_space_pirate) C++17
10 / 100
2000 ms 3320 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int n; ll k;
int a[maxn];

ll ways[maxn];


int viz[maxn];
int par[maxn];

int dfs(int at, ll k) {
    if (k==0) return at;
    if (viz[at]) {
	vector<int> v={at};
	for (int x=a[at]; x!=at; x=a[x]) {
	    v.push_back(x);
	}
	int len = v.size();
	k %= len;
	return v[k];
    }
    viz[at]=1;
    par[a[at]]=at;
    return dfs(a[at],k-1);    
}

void solve() {
    for (int i=0; i<n; i++) {
	viz[i]=0;
	par[i]=-1;
    }
    int dest = dfs(0, k);
    ways[dest]++;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>k;
    for (int i=0; i<n; i++) {
	cin>>a[i];
	--a[i];
    }

    for (int i=0; i<n; i++) {
	for (int j=0; j<n; j++) {
	    //cout<<i<<": "<<j<<endl;
	    int save=a[i];
	    a[i]=j;
	    solve();
	    a[i]=save;
	    
	}
    }
    for (int i=0; i<n; i++) {
	cout<<ways[i]<<"\n";
    }
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 11 ms 384 KB Output is correct
6 Correct 11 ms 384 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 12 ms 384 KB Output is correct
13 Correct 9 ms 384 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 11 ms 384 KB Output is correct
6 Correct 11 ms 384 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 12 ms 384 KB Output is correct
13 Correct 9 ms 384 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Execution timed out 2068 ms 496 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2073 ms 3320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 11 ms 384 KB Output is correct
6 Correct 11 ms 384 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 10 ms 512 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 12 ms 384 KB Output is correct
13 Correct 9 ms 384 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Execution timed out 2068 ms 496 KB Time limit exceeded
16 Halted 0 ms 0 KB -