Submission #105034

# Submission time Handle Problem Language Result Execution time Memory
105034 2019-04-10T09:10:58 Z bert30702 Ancient Books (IOI17_books) C++17
0 / 100
37 ms 31708 KB
#include <bits/stdc++.h>
#include "books.h"
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
const int MX = 1e6 + 100;
int boss[MX];
int Find(int u) {
	return boss[u] == u ? u : boss[u] = Find(boss[u]);
}
void merge(int a, int b) {
	boss[Find(a)] = Find(b);
}
priority_queue<int> pq[MX];
long long minimum_walk(vector<int> p, int s) {
	long long sum = 0;
	for(int i = 0; i < p.size(); i ++) boss[i] = i;
	for(int i = 0; i < p.size(); i ++) sum += abs(i - p[i]), merge(i, p[i]);
	vector<pair<int, pii> > E;
	for(int i = 0; i + 1 < p.size(); i ++) {
		if(p[i] == i and i != s) continue;
		int ptr = i + 1;
		if(ptr + 1 < p.size() and Find(p[ptr + 1]) == Find(i)) ptr ++;
		if(Find(ptr) != Find(i)) E.push_back({ptr - i, {i, ptr}});
	}
	sort(E.begin(), E.end());
	for(auto it: E) {
		if(Find(it.S.F) != Find(it.S.S)) {
			merge(it.S.F, it.S.S);
			sum += 2 * it.F;
		}
	}
	return sum;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i ++) boss[i] = i;
                 ~~^~~~~~~~~~
books.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i ++) sum += abs(i - p[i]), merge(i, p[i]);
                 ~~^~~~~~~~~~
books.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i + 1 < p.size(); i ++) {
                 ~~~~~~^~~~~~~~~~
books.cpp:24:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(ptr + 1 < p.size() and Find(p[ptr + 1]) == Find(i)) ptr ++;
      ~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31608 KB Output is correct
2 Correct 37 ms 31608 KB Output is correct
3 Correct 37 ms 31608 KB Output is correct
4 Correct 31 ms 31616 KB Output is correct
5 Incorrect 33 ms 31608 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31608 KB Output is correct
2 Correct 37 ms 31608 KB Output is correct
3 Correct 37 ms 31608 KB Output is correct
4 Correct 31 ms 31616 KB Output is correct
5 Incorrect 33 ms 31608 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31608 KB Output is correct
2 Correct 37 ms 31608 KB Output is correct
3 Correct 37 ms 31608 KB Output is correct
4 Correct 31 ms 31616 KB Output is correct
5 Incorrect 33 ms 31608 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 31708 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3116'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31608 KB Output is correct
2 Correct 37 ms 31608 KB Output is correct
3 Correct 37 ms 31608 KB Output is correct
4 Correct 31 ms 31616 KB Output is correct
5 Incorrect 33 ms 31608 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -