Submission #289301

# Submission time Handle Problem Language Result Execution time Memory
289301 2020-09-02T14:22:56 Z Touubs Ancient Books (IOI17_books) C++17
0 / 100
1 ms 256 KB
#include "books.h"
#include <bits/stdc++.h>

long long minimum_walk(std::vector<int> p, int s) {
    std::vector<bool> visited(p.size());
    long long res = 0;
    int maxVis = 0;
    int i;
    for (i = 0; i < p.size() && p[i] == i && i < s; i++);
    maxVis = i;
    for (; i < p.size(); i++) {
	if (maxVis < i && p[i] != i) {
	    res+=2 * (i - maxVis);
	    maxVis = std::max(maxVis, p[i]);
	} else if (maxVis >= i) {
	    maxVis = std::max(maxVis, p[i]);
	}
	res += abs(p[i] - i);
    }
    for (int i = p.size() - 1; p[i] == i && i >= s; res -= 2, i--);
    return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:9:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (i = 0; i < p.size() && p[i] == i && i < s; i++);
      |                 ~~^~~~~~~~~~
books.cpp:11:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (; i < p.size(); i++) {
      |            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '4', found: '2'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '4', found: '2'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '4', found: '2'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 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 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '4', found: '2'
6 Halted 0 ms 0 KB -