Submission #577906

#TimeUsernameProblemLanguageResultExecution timeMemory
577906Theo830고대 책들 (IOI17_books)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9; ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<int,int> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training ///Dremix10 's template const int N = 2e3+1; template<typename T> struct SPARSE{ vector<vector<T> > sparse; vector<int> log; const int maxPow = 22; int N; void init(int n){ sparse.assign(n,vector<T>(maxPow)); log.assign(n+1,0); N = n; for(int i = 2;i <= n;i++) log[i] = log[i/2] + 1; } // supports 0-indexing void build(T arr[]){ int i,j; for(i = 0;i < N ;i++) sparse[i][0] = arr[i]; for(j = 1;j < maxPow;j++) for(i = 0;i + (1<<j) <= N;i++) sparse[i][j] = min(sparse[i][j-1],sparse[i+(1<<(j-1))][j-1]); } T query(int l, int r){ int k = log[r-l+1]; return min(sparse[l][k],sparse[r-(1<<k)+1][k]); } }; template<typename T> struct SPARSE2{ vector<vector<T> > sparse; vector<int> log; const int maxPow = 22; int N; void init(int n){ sparse.assign(n,vector<T>(maxPow)); log.assign(n+1,0); N = n; for(int i = 2;i <= n;i++) log[i] = log[i/2] + 1; } // supports 0-indexing void build(T arr[]){ int i,j; for(i = 0;i < N ;i++) sparse[i][0] = arr[i]; for(j = 1;j < maxPow;j++) for(i = 0;i + (1<<j) <= N;i++) sparse[i][j] = max(sparse[i][j-1],sparse[i+(1<<(j-1))][j-1]); } T query(int l, int r){ int k = log[r-l+1]; return max(sparse[l][k],sparse[r-(1<<k)+1][k]); } }; SPARSE<ll>s; SPARSE2<ll>s2; #include "books.h" ll dp[1005][1005]; ll n; ll left[1005]; ll right[1005]; ll solve(ll i,ll j){ if(i == 0 && j == n-1){ return 0; } if(dp[i][j] != -1){ return dp[i][j]; } ll L = s.query(i,j),R = s2.query(i,j); if(i == L && j == R){ ll ans = min(solve(i + 1,j) + 2,solve(i,j + 1) + 2); return dp[i][j] = ans; } return dp[i][j] = solve(L,R); } long long minimum_walk(std::vector<int> p, int s) { ll ans = 0; n = p.size(); bool v[n] = {0}; ll dist = 0; ll l[n],r[n]; ll L = -1,R; if(p[s] == s){ L = R = s; rang.pb(ii(s,s)); } f(i,0,n){ left[i] = n; } f(i,0,n){ if(p[i] != i && !v[i]){ ll last = i; ll st = i; ll pos = p[i]; v[i] = 1; l[st] = i,r[st] = pos; while(pos != st){ l[st] = min(l[st],pos); r[st] = max(r[st],pos); v[pos] = 1; ans += abs(pos - last); last = pos; pos = p[pos]; } ans += abs(pos - last); l[st] = min(l[st],pos); r[st] = max(r[st],pos); rang.pb(ii(l[st],r[st])); if(v[s] == 1 && L == -1){ L = l[st]; R = r[st]; } } } if(rang.empty()){ return ans; } for(auto x:rang){ left[x.S] = min(left[x.S],x.F); right[x.F] = max(right[x.F],x.S); } s.init(n); s2.init(n); s.build(left); s2.build(right); memset(dp,-1,sizeof dp); dist = solve(L,R); ans += 2 * dist; return ans; } /* int main() { int n, s; assert(2 == scanf("%d %d", &n, &s)); vector<int> 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 (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:123:9: error: 'rang' was not declared in this scope; did you mean 'rand'?
  123 |         rang.pb(ii(s,s));
      |         ^~~~
      |         rand
books.cpp:126:9: error: reference to 'left' is ambiguous
  126 |         left[i] = n;
      |         ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
books.cpp:98:4: note:                 'll left [1005]'
   98 | ll left[1005];
      |    ^~~~
books.cpp:146:13: error: 'rang' was not declared in this scope; did you mean 'rand'?
  146 |             rang.pb(ii(l[st],r[st]));
      |             ^~~~
      |             rand
books.cpp:153:8: error: 'rang' was not declared in this scope; did you mean 'rand'?
  153 |     if(rang.empty()){
      |        ^~~~
      |        rand
books.cpp:156:16: error: 'rang' was not declared in this scope; did you mean 'rand'?
  156 |     for(auto x:rang){
      |                ^~~~
      |                rand
books.cpp:157:9: error: reference to 'left' is ambiguous
  157 |         left[x.S] = min(left[x.S],x.F);
      |         ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
books.cpp:98:4: note:                 'll left [1005]'
   98 | ll left[1005];
      |    ^~~~
books.cpp:157:25: error: reference to 'left' is ambiguous
  157 |         left[x.S] = min(left[x.S],x.F);
      |                         ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
books.cpp:98:4: note:                 'll left [1005]'
   98 | ll left[1005];
      |    ^~~~
books.cpp:158:9: error: reference to 'right' is ambiguous
  158 |         right[x.F] = max(right[x.F],x.S);
      |         ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
books.cpp:99:4: note:                 'll right [1005]'
   99 | ll right[1005];
      |    ^~~~~
books.cpp:158:26: error: reference to 'right' is ambiguous
  158 |         right[x.F] = max(right[x.F],x.S);
      |                          ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
books.cpp:99:4: note:                 'll right [1005]'
   99 | ll right[1005];
      |    ^~~~~
books.cpp:160:7: error: request for member 'init' in 's', which is of non-class type 'int'
  160 |     s.init(n);
      |       ^~~~
books.cpp:162:7: error: request for member 'build' in 's', which is of non-class type 'int'
  162 |     s.build(left);
      |       ^~~~~
books.cpp:162:13: error: reference to 'left' is ambiguous
  162 |     s.build(left);
      |             ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
books.cpp:98:4: note:                 'll left [1005]'
   98 | ll left[1005];
      |    ^~~~
books.cpp:163:14: error: reference to 'right' is ambiguous
  163 |     s2.build(right);
      |              ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from books.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
books.cpp:99:4: note:                 'll right [1005]'
   99 | ll right[1005];
      |    ^~~~~