Submission #390581

# Submission time Handle Problem Language Result Execution time Memory
390581 2021-04-16T10:46:45 Z mehrdad_sohrabi Ancient Books (IOI17_books) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=1e6+10;

ll vis[N];

long long minimum_walk(std::vector<int32_t> p, int32_t s) {
    vector <pii> baz;
    ll n=p.size();
    ll ans=0;
    for (int i=0;i<n;i++){
        if (vis[i]) continue;
        ll mn=i,mx=i;
        ll j=p[i];
        ans+=abs(p[i]-i);
        while(j!=i){
            ans+=abs(p[j]-j);
        //    cout << j << " " << p[j] << endl;
            mn=min(mn,j);
            mx=max(mx,j);
            vis[j]=1;
            j=p[j];
        }
        vis[i]=1;
        baz.pb({mn,-mx});
    }
 //   cout << ans << endl;
    sort(baz.begin(),baz.end());
    vector <pii> a;
    a.pb(baz[0]);
    for (int i=1;i<baz.size();i++){
        pii p=baz[i],q=a.back();
        if (-p.S<=-q.S) continue;
        if (p.F<=-q.S){
            a.pop_back();
            q.S=p.S;
            a.pb(q);
        }
        else
            a.pb(baz[i]);
    }
    ans+=a.back().F*2;
    return ans;
}
/*
int32_t main() {
	int32_t n, s;
	assert(2 == scanf("%d %d", &n, &s));

	vector<int32_t> 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;
}
*/
/*
4 0
0 2 3 1
*/

Compilation message

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