제출 #117673

#제출 시각아이디문제언어결과실행 시간메모리
117673sealnot123고대 책들 (IOI17_books)C++14
50 / 100
168 ms23928 KiB
#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;
LL qsl[N],qsr[N];
long long minimum_walk(vector<int> p, int s) {
    int a,b,c,d,i,j,k;
    n = SZ(p);
    if(n==1) return 0;
    for(i=0;i<n;i++){
        a = p[i];
        b = i;
        if(a==b) continue;
        if(a>b) qsl[b]++,qsl[a]--;
        else qsr[a]++,qsr[b]--;
        if(a<s && b>s){
            if(s-a <= b-s) qsr[a]++,qsr[s]--;
            else qsl[s]++,qsl[b]--;
        }
    }
    for(i=1;i<n;i++) qsl[i]+=qsl[i-1],qsr[i]+=qsr[i-1];
//    for(i=0;i<n;i++) printf("%lld ",qsl[i]);
//    printf("\n");
//    for(i=0;i<n;i++) printf("%lld ",qsr[i]);
//    printf("\n");
    int l,r;
    for(i=0;i<n;i++){
        l = i;
        if(qsl[i] || qsr[i]) break;
    }
    for(i=n-1;i>=0;i--){
        r = i;
        if(qsl[i] || qsr[i]) break;
    }
    if(l>r) return 0;
    LL ans = 0;
    for(i=s;i<=r;i++) ans += max(1ll,max(qsl[i],qsr[i]));
    for(i=s-1;i>=l;i--) ans += max(1ll,max(qsl[i],qsr[i]));
    return 2*ans;
}

컴파일 시 표준 에러 (stderr) 메시지

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:20:13: warning: unused variable 'c' [-Wunused-variable]
     int a,b,c,d,i,j,k;
             ^
books.cpp:20:15: warning: unused variable 'd' [-Wunused-variable]
     int a,b,c,d,i,j,k;
               ^
books.cpp:20:19: warning: unused variable 'j' [-Wunused-variable]
     int a,b,c,d,i,j,k;
                   ^
books.cpp:20:21: warning: unused variable 'k' [-Wunused-variable]
     int a,b,c,d,i,j,k;
                     ^
books.cpp:39:11: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int l,r;
           ^
books.cpp:39:9: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int l,r;
         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...