Submission #117724

# Submission time Handle Problem Language Result Execution time Memory
117724 2019-06-17T07:04:18 Z sealnot123 Ancient Books (IOI17_books) C++14
0 / 100
2 ms 384 KB
#include "books.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
const int N = 1000007;
int n;
int mk[N];
vector<PII> inter,interx;
long long minimum_walk(vector<int> p, int s) {
    int a,b,c,d,i,j,k;
    int l,r;
    LL ans = 0;
    n = SZ(p);
    if(n==1) return 0;
    for(i=0;i<n;i++){
        if(p[i]==i || mk[i]) continue;
        l = r = i;
        mk[i] = 1;
        a = p[i];
        ans += abs(i-p[i]);
        while(a!=i){
            mk[a] = 1;
            ans += abs(a-p[a]);
            l = min(l, a);
            r = max(r, a);
            a = p[a];
        }
        inter.pb({l,r});
    }
//    sort(inter.begin(),inter.end());
//    l = r = -1;
//    for(PII it : inter){
//        if(it.x > r){
//            if(l!=-1) interx.pb({l,r});
//            l = it.x;
//        }
//        r = max(r, it.y);
//    }
//    if(l!=-1) interx.pb({l,r});
//    for(i=0;i<SZ(interx);i++){
//        PII it1 = interx[i];
////        printf("%d %d\n",it1.x,it1.y);
//        if(it1.x<=s && it1.y>=s){
//            ans += 2*min(s-it1.x,it1.y-s);
//        }
//        if(i+1==SZ(interx)) continue;
//        PII it2 = interx[i+1];
//        ans += 2*(it2.x-it1.y);
//    }
    return ans;
}
/*
7 4
1 0 6 5 4 2 3
*/

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:21:11: warning: unused variable 'b' [-Wunused-variable]
     int a,b,c,d,i,j,k;
           ^
books.cpp:21:13: warning: unused variable 'c' [-Wunused-variable]
     int a,b,c,d,i,j,k;
             ^
books.cpp:21:15: warning: unused variable 'd' [-Wunused-variable]
     int a,b,c,d,i,j,k;
               ^
books.cpp:21:19: warning: unused variable 'j' [-Wunused-variable]
     int a,b,c,d,i,j,k;
                   ^
books.cpp:21:21: warning: unused variable 'k' [-Wunused-variable]
     int a,b,c,d,i,j,k;
                     ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 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 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -