Submission #1045322

# Submission time Handle Problem Language Result Execution time Memory
1045322 2024-08-05T20:26:11 Z beaconmc Ancient Books (IOI17_books) C++14
0 / 100
0 ms 348 KB
#include "books.h"

#include <bits/stdc++.h>

 
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;


long long minimum_walk(vector<int> p, int s) {
	vector<bool> visited;
	vector<ll> maxis;
	for (auto&i : p) visited.push_back(0), maxis.push_back(-1);

	FOR(i,0,p.size()){
		vector<ll> stuff;
		ll temp = p[i];
		ll maxi = i;
		if (visited[temp]) continue;
		visited[temp] = 1;
		temp = p[i];
		stuff.push_back(p[p[i]]);
		while (temp != i){
			maxi = max(maxi, temp);
			visited[temp] = 1;
			temp = p[temp];
			visited[temp] = 1;
			stuff.push_back(temp);
		}
		for (auto&k : stuff){
			maxis[k] = maxi;
		}
	}

	ll cur = 0;
	ll ans = 0;
	FOR(i,0,p.size()){
		ans += abs(p[i]-i);
	}

	while (cur < p.size()-1){
		if (cur == maxis[cur]) ans++, cur++;
		else cur = maxis[cur];
	}
	return ans;

}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:16:12: warning: unused variable 'i' [-Wunused-variable]
   16 |  for (auto&i : p) visited.push_back(0), maxis.push_back(-1);
      |            ^
books.cpp:7:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   18 |  FOR(i,0,p.size()){
      |      ~~~~~~~~~~~~                
books.cpp:18:2: note: in expansion of macro 'FOR'
   18 |  FOR(i,0,p.size()){
      |  ^~~
books.cpp:7:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   40 |  FOR(i,0,p.size()){
      |      ~~~~~~~~~~~~                
books.cpp:40:2: note: in expansion of macro 'FOR'
   40 |  FOR(i,0,p.size()){
      |  ^~~
books.cpp:44:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  while (cur < p.size()-1){
      |         ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -