Submission #968243

# Submission time Handle Problem Language Result Execution time Memory
968243 2024-04-23T08:42:06 Z nguyentunglam Ancient Books (IOI17_books) C++17
Compilation error
0 ms 0 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;


long long minimum_walk(std::vector<int> p, int s) {
  int n = p.size();
  vector<int> vis(n);
  int last = 0;
  long long ans = 0;
  for(int i = 0; i < n; i++) if (!vis[i]) {
    last = i;
    int cur = i;
    vis[cur] = 0;
    int pre = cur;
    cur = p[cur];
    while (!vis[cur]) {
      vis[cur] = 1;
      ans += abs(pre - cur);
      pre = cur;
      cur = p[cur];
    }
  }
  ans += last * 2;
	return ans;
}

int main() {
  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);
	int n, s;
	assert(2 == scanf("%d %d", &n, &s));

	vector<int> p((unsigned) n);
	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &p[(unsigned) i]));

	long long res = minimum_walk(p, s);
	printf("%lld\n", res);

	return 0;
}

Compilation message

books.cpp: In function 'int main()':
books.cpp:29:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   freopen ("task.inp", "r", stdin);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
books.cpp:30:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   freopen ("task.out", "w", stdout);
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cciOXgJX.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccDfdUmY.o:books.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status