제출 #117950

#제출 시각아이디문제언어결과실행 시간메모리
117950sealnot123고대 책들 (IOI17_books)C++14
50 / 100
251 ms19960 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; int mk[N]; vector<PII> inter,interx; int L[N],R[N],G[N]; void extend(int &l, int &r, int ll, int rr){ ll = min(ll, min(L[G[l]], L[G[r]])); rr = max(rr, max(R[G[l]], R[G[r]])); while(ll < l || r < rr){ if(ll < l){ l--; ll = min(ll, L[G[l]]); rr = max(rr, R[G[l]]); }else{ r++; ll = min(ll, L[G[r]]); rr = max(rr, R[G[r]]); } } } LL step(int l, int r, int ll, int rr){ LL ans = 0; int i,j,k,a,b,c; while(ll < l || r < rr){ int stepl = 0, stepr = 0, ch = 0; int xll, xrr, xl, xr; xl = xll = l; xr = xrr = r; while(xl > ll && xrr == r){ stepl += 2; xl--; extend(xl, xr, xll, xrr); } if(xrr == r) ch = 1; xl = xll = l; xr = xrr = r; while(xr < rr && xll == l){ stepr += 2; xr++; extend(xl, xr, xll, xrr); } if(xll == l) ch = 1; if(ch){ ans += stepl + stepr; break; }else{ ans += min(stepl, stepr); extend(l, r, xll, xrr); } } return ans; } long long minimum_walk(vector<int> p, int s) { int a, b, c = 0, d, i, j, k; int l = s, r = s; LL ans = 0; n = SZ(p); for(i=0; i<n; i++){ ans += abs(i - p[i]); if(!G[i]){ c++; a = i; L[c] = R[c] = i; do{ G[a] = c; L[c] = min(L[c], a); R[c] = max(R[c], a); a = p[a]; }while(a != i); if(i != p[i]){ l = min(l, L[c]); r = max(r, R[c]); } } } int ll=s, rr=s; extend(ll, rr, L[G[s]], R[G[s]]); // printf("%lld %d %d : %d %d\n", ans, l, r, ll, rr); return ans + step(ll, rr, l, r); } /* 4 0 2 0 1 3 7 4 1 0 6 5 4 2 3 8 4 7 1 2 0 3 5 6 4 8 4 7 5 6 0 3 2 1 4 5 2 3 4 2 0 1 */

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

books.cpp: In function 'LL step(int, int, int, int)':
books.cpp:38:9: warning: unused variable 'i' [-Wunused-variable]
     int i,j,k,a,b,c;
         ^
books.cpp:38:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j,k,a,b,c;
           ^
books.cpp:38:13: warning: unused variable 'k' [-Wunused-variable]
     int i,j,k,a,b,c;
             ^
books.cpp:38:15: warning: unused variable 'a' [-Wunused-variable]
     int i,j,k,a,b,c;
               ^
books.cpp:38:17: warning: unused variable 'b' [-Wunused-variable]
     int i,j,k,a,b,c;
                 ^
books.cpp:38:19: warning: unused variable 'c' [-Wunused-variable]
     int i,j,k,a,b,c;
                   ^
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:69:12: warning: unused variable 'b' [-Wunused-variable]
     int a, b, c = 0, d, i, j, k;
            ^
books.cpp:69:22: warning: unused variable 'd' [-Wunused-variable]
     int a, b, c = 0, d, i, j, k;
                      ^
books.cpp:69:28: warning: unused variable 'j' [-Wunused-variable]
     int a, b, c = 0, d, i, j, k;
                            ^
books.cpp:69:31: warning: unused variable 'k' [-Wunused-variable]
     int a, b, c = 0, d, i, j, k;
                               ^
#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...