답안 #497992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497992 2021-12-24T08:17:12 Z 600Mihnea 우주 해적 (JOI14_space_pirate) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = (int) 1e5 + 7;
int n;
int nxt[N];
bool vis[N];
ll solution[N];
ll k;


int main() {
  ios::sync_with_stdio(0); cin.tie(0);

  //freopen ("input", "r", stdin);

  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> nxt[i];
  }


  for (int a = 1; a <= n; a++) {
    int init = nxt[a];
    for (int b = 1; b <= n; b++) {
      for (int i = 1; i <= n; i++) {
        vis[i] = 0;
      }
      vector<int> path, cycle;
      nxt[a] = b;


      int c = solve();

      int current = 1;
      ll need = 0;
      for (ll step = 1; step <= k; step++) {
        if (!vis[current]) {
          vis[current] = 1;
          path.push_back(current);
        } else {
          need = k - step + 1;
          assert(need > 0);
          bool has = 0;
          for (auto &x : path) {
            if (x == current) {
              has = 1;
            }
            if (has) {
              cycle.push_back(x);
            }
          }
          break;
        }
        current = nxt[current];
      }

      /**

      1 2 3

      **/

      if (need) {
        need %= (int) cycle.size();
        for (int step = 1; step <= need; step++) {
          current = nxt[current];
        }
      }
      solution[current]++;
    }
    nxt[a] = init;
  }

  for (int i = 1; i <= n; i++) {
    cout << solution[i] << "\n";
  }



  return 0;
}

Compilation message

space_pirate.cpp: In function 'int main()':
space_pirate.cpp:35:15: error: 'solve' was not declared in this scope
   35 |       int c = solve();
      |               ^~~~~
space_pirate.cpp:35:11: warning: unused variable 'c' [-Wunused-variable]
   35 |       int c = solve();
      |           ^