Submission #119123

#TimeUsernameProblemLanguageResultExecution timeMemory
119123tinjyuAncient Books (IOI17_books)C++14
0 / 100
2 ms384 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long int tag[1000005]; int l[1000005],r[1000005]; long long int ans; long long minimum_walk(std::vector<int> p, int s) { int n=p.size(); int t=0; int far=0; for(int i=0;i<n;i++) { ans+=abs(i-p[i]); if(i>p[i]) { tag[p[i]]++; tag[i+1]--; } else { tag[i]++; tag[p[i]+1]--; } } int l=n-1; for(int i=n-1;i>=0;i--) { if(tag[i]<0)break; l=i-1; } int tmp=0; for(int i=0;i<=l;i++) { tmp+=tag[i]; if(tmp==0)ans+=2; } return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:9:6: warning: unused variable 't' [-Wunused-variable]
  int t=0;
      ^
books.cpp:10:6: warning: unused variable 'far' [-Wunused-variable]
  int far=0;
      ^~~
#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...