답안 #52306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52306 2018-06-25T08:57:37 Z 강태규(#1345) 우주 해적 (JOI14_space_pirate) C++11
0 / 100
2000 ms 2024 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
llong k;
int nxt[100001];
int dist[100001];
int sz[100001];
llong ans[100001];
int main() {
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; ++i) {
        scanf("%d", nxt + i);
	}
	
	
	for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 1; k <= n; ++k) {
                dist[k] = -1;
            }
            int tp = nxt[i];
            nxt[i] = j;
            
            int cyc, s;
            for (int k = 1, m = 0; ; k = nxt[k], ++m) {
                if (dist[k] != -1) {
                   cyc = m - dist[k];
                   s = k;
                   break; 
                }
                dist[k] = m;
            }
            int x = 1;
            for (int d = (k - dist[s]) % cyc; d--; ) {
                x = nxt[x];
            }
            
            ++ans[x];
            nxt[i] = tp;
        }
	}
	
	for (int i = 1; i <= n; ++i) {
        printf("%lld\n", ans[i]);
	}
	return 0;
}

Compilation message

space_pirate.cpp: In function 'int main()':
space_pirate.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~
space_pirate.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", nxt + i);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2076 ms 2024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -