Submission #289079

# Submission time Handle Problem Language Result Execution time Memory
289079 2020-09-02T10:29:52 Z JoMee Ancient Books (IOI17_books) C++17
0 / 100
1 ms 384 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,n) for(int i = a; i<n; i++)
#define per(i,a,n) for(int i = n-1; i>=a; i--)

long long minimum_walk(vector<int> p, int s) {
	vector<long long> sm(p.size(),0);
	rep(i,0,p.size()){
		if(i < p[i])sm[i]++,sm[p[i]]--;
	}
	rep(i,1,sm.size())sm[i] += sm[i-1];

	int rm = s;
	per(i,s,p.size()){
		if(sm[i] != 0){
			rm = i;
			break;
		}
	}
	rm++;
	int lm = s;
	rep(i,0,s){
		if(sm[i] != 0){
			lm = i;
			break;
		}
	}
	long long res = 0;
	rep(i,0,rm){
		if(sm[i] != 0)res+=2*(sm[i]-1);
	}
	cout<<lm<<" "<<rm<<endl;
	res += 2*(rm-lm);
	return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,n) for(int i = a; i<n; i++)
......
   10 |  rep(i,0,p.size()){
      |      ~~~~~~~~~~~~                   
books.cpp:10:2: note: in expansion of macro 'rep'
   10 |  rep(i,0,p.size()){
      |  ^~~
books.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,n) for(int i = a; i<n; i++)
......
   13 |  rep(i,1,sm.size())sm[i] += sm[i-1];
      |      ~~~~~~~~~~~~~                  
books.cpp:13:2: note: in expansion of macro 'rep'
   13 |  rep(i,1,sm.size())sm[i] += sm[i-1];
      |  ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB secret mismatch
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB secret mismatch
2 Halted 0 ms 0 KB -