Submission #2303564
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} struct UnionFindTree{ vector<int>par,sz; UnionFindTree(int n){ par.resize(n); sz.resize(n); for(int i=0;i<n;i++){ par[i]=i; sz[i]=1; } } int find(int x){ return x==par[x]?x:par[x]=find(par[x]); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y)return; if(sz[x]<sz[y])swap(x,y); sz[x]+=sz[y]; par[y]=x; } bool areSame(int x,int y){ return find(x)==find(y); } int size(int x){ return sz[find(x)]; } }; int N; int A[222222]; int X[222222]; int dp[222222]; int ans[1000001]; signed main(){ cin>>N; rep(i,N-1)cin>>A[i]; int M;cin>>M; rep(i,M)cin>>X[i]; UnionFindTree uf(1000001); deque<int>dp(1000001); rep(i,1000001)dp[i]=i; for(int i=N-2;i>=2;i--){ vint v; rep(j,A[i]){ v.pb(dp.front()); dp.pop_front(); dp.push_back(-1); } rep(j,A[i]){ if(v[j]!=-1&&dp[A[i]-j]!=-1)uf.unite(v[j],dp[A[i]-j]); if(v[j]!=-1)dp[A[i]-j]=v[j]; } } rep(i,1000001)if(dp[i]!=-1)ans[uf.find(dp[i])]=i; rep(i,1000001)ans[i]=ans[uf.find(i)]; int sum=0; for(int i=2;i<N-1;i++)sum+=A[i]; rep(i,M){ int tmp; if(X[i]>1000000)tmp=X[i]-sum; else tmp=ans[X[i]]; cout<<tmp+A[0]-A[1]<<endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | H - Tokaido |
User | latte0119 |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 1948 Byte |
Status | AC |
Exec Time | 483 ms |
Memory | 41856 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | 900 / 900 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
dataset1 | sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt |
dataset2 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 106 ms | 37120 KB |
01-02.txt | AC | 23 ms | 36352 KB |
01-03.txt | AC | 38 ms | 36608 KB |
01-04.txt | AC | 79 ms | 36480 KB |
01-05.txt | AC | 106 ms | 37120 KB |
01-06.txt | AC | 106 ms | 37120 KB |
01-07.txt | AC | 65 ms | 36480 KB |
01-08.txt | AC | 106 ms | 37120 KB |
01-09.txt | AC | 105 ms | 37120 KB |
01-10.txt | AC | 39 ms | 38136 KB |
01-11.txt | AC | 42 ms | 38528 KB |
01-12.txt | AC | 73 ms | 37752 KB |
01-13.txt | AC | 77 ms | 38976 KB |
01-14.txt | AC | 75 ms | 37356 KB |
01-15.txt | AC | 76 ms | 38508 KB |
01-16.txt | AC | 65 ms | 38896 KB |
01-17.txt | AC | 54 ms | 36864 KB |
01-18.txt | AC | 54 ms | 36864 KB |
01-19.txt | AC | 54 ms | 36864 KB |
02-01.txt | AC | 102 ms | 36736 KB |
02-02.txt | AC | 483 ms | 39040 KB |
02-03.txt | AC | 476 ms | 37632 KB |
02-04.txt | AC | 479 ms | 37504 KB |
02-05.txt | AC | 405 ms | 37376 KB |
02-06.txt | AC | 470 ms | 37504 KB |
02-07.txt | AC | 482 ms | 37632 KB |
02-08.txt | AC | 418 ms | 41856 KB |
02-09.txt | AC | 415 ms | 37944 KB |
02-10.txt | AC | 426 ms | 37820 KB |
02-11.txt | AC | 446 ms | 38580 KB |
02-12.txt | AC | 440 ms | 38764 KB |
02-13.txt | AC | 440 ms | 38764 KB |
02-14.txt | AC | 428 ms | 38628 KB |
02-15.txt | AC | 419 ms | 38528 KB |
02-16.txt | AC | 417 ms | 38400 KB |
sample-01.txt | AC | 23 ms | 36352 KB |
sample-02.txt | AC | 22 ms | 36352 KB |