QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528027#4207. Uplifting ExcursionAdamGS20 2517ms37436kbC++231.7kb2024-08-23 04:05:052024-08-23 04:05:05

Judging History

你现在查看的是最新测评结果

  • [2024-08-23 04:05:05]
  • 评测
  • 测评结果:20
  • 用时:2517ms
  • 内存:37436kb
  • [2024-08-23 04:05:05]
  • 提交

answer

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(a, b) for(int a = 0; a < (b); ++a)
    #define st first
    #define nd second
    #define pb push_back
    #define all(a) a.begin(), a.end()
    const ll INF=1e18+7;
    const ll LIM=1e6+7;
    ll dp[LIM], dp2[LIM], A[LIM], B[LIM];
    int main() {
    	ios_base::sync_with_stdio(0); cin.tie(0);
    	ll n, m;
    	cin >> n >> m;
    	rep(i, n) cin >> A[n-i];
    	rep(i, n+1) cin >> B[i];
    	ll ans=0;
    	rep(i, n+1) ans+=B[i];
    	rep(i, n+1) ans+=A[i];
    	rep(i, n+1) m+=A[i]*(ll)i;
    	rep(i, n+1) m-=B[i]*(ll)i;
    	if(m<0) {
    		m*=-1;
    		rep(i, n+1) swap(A[i], B[i]);
    	}
    	rep(i, LIM) dp[i]=INF;
    	dp[0]=0;
    	for(ll i=n; i; --i) {
    		if(m>=LIM/2) {
    			ll p=m-LIM/2;
    			p=(p+i-1)/i;
    			p=min(p, A[i]);
    			A[i]-=p;
    			dp[0]+=p;
    			m-=p*i;	
    		}
    	}
    	if(m>=LIM) {
    		cout << "impossible\n";
    		return 0;
    	}
    	rep(xd, 2) {
    		for(ll i=1; i<=n; ++i) {
    			vector<ll>V[i], l(i);
    			rep(j, LIM) {
    				ll p=j%i;
    				while(l[p]<V[p].size() && (j-V[p][l[p]])/i>A[i]) ++l[p];
    				while(V[p].size()>0 && dp[j]<=dp[V[p].back()]+(j-V[p].back())/i) {
    					V[p].pop_back();
    					l[p]=min(l[p], (ll)V[p].size());
    				}
    				dp2[j]=dp[j];
    				if(l[p]<V[p].size()) {
    					dp2[j]=min(dp2[j], dp[V[p][l[p]]]+(j-V[p][l[p]])/i);
    				}
    				V[p].pb(j);
    			}
    			rep(j, LIM) dp[j]=dp2[j];
    		}
    		rep(i, LIM/2) swap(dp[i], dp[LIM-i-1]);
    		rep(i, n+1) swap(A[i], B[i]);
    	}
    	if(dp[m]==INF) {
    		cout << "impossible\n";
    		return 0;
    	}
    	cout << ans-dp[m] << '\n';
    }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 28ms
memory: 22304kb

input:

1 5
0 0 6

output:

5

result:

ok single line: '5'

Test #2:

score: 5
Accepted
time: 987ms
memory: 23152kb

input:

50 2303
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 5 25 50 0

output:

47

result:

ok single line: '47'

Test #3:

score: 5
Accepted
time: 1186ms
memory: 22980kb

input:

50 -17964
18 21 8 47 11 30 0 34 11 22 10 29 14 39 25 42 16 47 6 39 0 4 28 5 4 39 43 47 14 49 24 37 22 47 23 31 18 28 43 14 44 26 46 40 27 17 41 7 13 25 27 20 17 13 23 30 9 16 5 25 46 22 35 44 34 39 19 19 33 11 30 30 41 20 1 9 39 34 31 26 28 13 13 21 45 11 32 30 35 37 22 31 1 9 43 18 31 41 34 39 2

output:

2060

result:

ok single line: '2060'

Test #4:

score: 5
Accepted
time: 67ms
memory: 22540kb

input:

3 5
3 1 0 2 0 0 2

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 5
Accepted
time: 238ms
memory: 21692kb

input:

10 7
0 0 0 0 0 0 0 0 0 0 7 10 5 8 10 0 9 0 4 6 2

output:

14

result:

ok single line: '14'

Test #6:

score: 5
Accepted
time: 0ms
memory: 14072kb

input:

50 -779348731063743410
36 40 12 5 42 47 17 35 47 44 16 45 5 41 26 7 28 23 15 27 17 19 44 18 12 30 27 13 24 5 34 11 36 39 38 32 0 34 24 11 18 26 43 50 1 29 18 28 41 38 41 19 22 0 9 30 18 36 0 21 41 7 25 10 17 9 48 9 37 7 49 13 23 9 15 25 35 10 43 27 5 45 42 33 8 30 36 20 49 24 31 42 3 27 16 45 11 33 ...

output:

impossible

result:

ok single line: 'impossible'

Test #7:

score: 5
Accepted
time: 1194ms
memory: 23440kb

input:

50 -51601
47 45 49 46 49 48 45 45 46 47 50 49 48 48 49 48 48 46 50 49 45 46 47 49 45 47 49 47 50 48 46 46 50 45 48 49 49 46 49 49 48 47 49 47 49 45 49 50 45 45 47 50 46 49 49 45 48 46 48 48 45 46 46 49 48 49 45 47 50 46 47 45 45 49 49 47 45 47 47 47 49 47 50 45 46 48 49 47 49 48 47 48 45 45 45 49 46...

output:

3319

result:

ok single line: '3319'

Test #8:

score: 5
Accepted
time: 1183ms
memory: 21704kb

input:

50 1853
16 29 35 41 32 44 9 45 28 2 32 40 13 47 16 7 49 42 0 34 15 22 3 34 7 31 5 23 40 30 10 2 36 46 46 9 24 12 9 46 46 19 19 29 9 22 28 12 44 31 46 41 4 5 27 38 31 32 38 30 41 43 36 30 21 42 19 12 8 49 43 17 17 2 49 49 12 47 20 47 14 2 21 16 45 45 35 41 33 6 28 19 28 45 41 15 25 28 5 4 35

output:

2683

result:

ok single line: '2683'

Test #9:

score: 5
Accepted
time: 48ms
memory: 22808kb

input:

2 5
2 3 1 1 4

output:

9

result:

ok single line: '9'

Test #10:

score: 5
Accepted
time: 979ms
memory: 21652kb

input:

50 2303
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 48 0

output:

63

result:

ok single line: '63'

Test #11:

score: 5
Accepted
time: 1158ms
memory: 21636kb

input:

50 -11347
0 0 30 10 0 0 15 0 13 16 34 21 0 0 23 0 2 3 43 0 0 0 41 0 0 5 0 0 10 0 26 0 0 0 0 30 12 0 0 13 0 10 0 0 1 0 38 0 5 0 0 0 0 0 0 0 28 0 0 0 29 0 12 49 26 0 0 0 0 46 10 45 49 0 0 0 29 0 30 46 30 0 17 0 39 27 0 0 0 14 27 0 0 31 0 13 0 0 23 0 29

output:

impossible

result:

ok single line: 'impossible'

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #12:

score: 15
Accepted
time: 2352ms
memory: 22008kb

input:

100 95010
0 83 18 41 0 95 77 84 0 20 22 0 0 0 0 0 26 50 0 1 0 54 86 34 0 0 55 0 0 38 12 42 0 28 0 0 0 1 3 24 0 96 61 0 0 70 37 0 0 15 51 0 0 0 0 69 1 0 20 7 0 49 71 0 0 0 0 0 0 0 28 62 56 0 0 23 0 71 0 0 52 42 0 0 0 0 0 87 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 77 34 0 2 0 0 0 0 64 0 0 66 0...

output:

impossible

result:

ok single line: 'impossible'

Test #13:

score: 15
Accepted
time: 1942ms
memory: 22308kb

input:

100 9603
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

133

result:

ok single line: '133'

Test #14:

score: 15
Accepted
time: 2448ms
memory: 24228kb

input:

100 13237
2 100 82 74 17 71 16 3 9 27 70 61 19 42 29 96 81 11 70 51 60 41 54 34 21 6 63 50 11 97 61 77 20 97 39 36 86 10 75 35 87 20 62 4 16 42 95 97 18 75 64 62 15 94 39 44 47 23 88 80 83 1 46 40 56 83 89 14 55 29 73 53 32 71 35 67 74 91 54 19 20 19 38 40 37 64 45 65 20 56 45 96 6 47 63 72 90 10 21...

output:

10052

result:

ok single line: '10052'

Test #15:

score: 15
Accepted
time: 0ms
memory: 14996kb

input:

100 628885114412155579
51 25 68 85 83 83 60 34 62 36 34 38 35 85 41 65 56 98 63 97 94 85 39 33 34 88 24 81 10 63 42 37 69 50 72 99 10 36 97 21 2 16 46 55 73 46 40 24 55 79 64 19 31 88 3 27 61 20 46 31 6 81 76 22 80 44 37 67 75 37 58 22 83 76 52 45 85 47 49 85 60 34 79 42 26 43 95 94 36 76 55 59 70 6...

output:

impossible

result:

ok single line: 'impossible'

Test #16:

score: 15
Accepted
time: 2517ms
memory: 24680kb

input:

100 -249726
98 95 100 95 96 97 98 98 99 97 100 99 99 96 96 97 98 96 96 98 97 97 99 97 99 99 97 100 99 95 99 99 99 97 95 98 99 95 95 97 97 97 97 95 95 99 99 99 97 96 97 97 98 100 98 98 98 95 95 95 98 98 96 98 97 97 98 99 98 98 99 99 96 98 99 100 98 95 99 98 96 99 95 97 99 96 97 98 100 99 98 99 97 96 ...

output:

16659

result:

ok single line: '16659'

Test #17:

score: 15
Accepted
time: 2505ms
memory: 25540kb

input:

100 -421916
99 96 98 97 99 95 97 95 98 99 95 98 99 99 98 98 98 96 95 98 99 95 97 98 98 95 95 96 99 99 95 95 97 95 97 97 96 97 97 96 95 95 96 96 96 97 97 98 99 99 97 97 97 97 99 97 98 97 99 95 95 99 95 99 99 96 95 97 99 97 98 98 99 96 98 99 96 97 97 100 96 98 96 96 96 100 96 97 95 97 95 98 99 97 97 9...

output:

13395

result:

ok single line: '13395'

Test #18:

score: 15
Accepted
time: 1943ms
memory: 21348kb

input:

100 9603
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

157

result:

ok single line: '157'

Subtask #3:

score: 0
Wrong Answer

Test #19:

score: 10
Accepted
time: 723ms
memory: 33288kb

input:

30 38887954194235
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 444113827766 26 511237030935 22 696666627923 315938808146 20 952560827478 924020644151 850666790939 23 587888300072 23 797812801251 911390834853 677171102320 4 2 22 950650764450 278888113729 23 15 15 13 9 637120041802 20 1...

output:

5692035643249

result:

ok single line: '5692035643249'

Test #20:

score: 10
Accepted
time: 782ms
memory: 25380kb

input:

30 76226675150141
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 17 25 575187266854 933205256851 30642958327 5 723752635947 251949849516 20 241825198172 10 8 19 416001319998 846220673515 292065146547 9 17 329305181338 3 153818277782 4 622464956364 2 18 543111965233 5 20 24 8

output:

5959550686625

result:

ok single line: '5959550686625'

Test #21:

score: 10
Accepted
time: 617ms
memory: 21712kb

input:

30 783
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 842682060204 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 5 5 812222496404 0

output:

842682060231

result:

ok single line: '842682060231'

Test #22:

score: 10
Accepted
time: 796ms
memory: 33720kb

input:

30 63681107909129
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 29 28 25 28 162867113393 396607890615 26 27 29 27 29 29 98874364794 27 26 28 25 28 298317942689 473749524449 27 29 25 29 738708341359 378923162064 903755880355 985915633657 113061161327 29

output:

3130974862204

result:

ok single line: '3130974862204'

Test #23:

score: 10
Accepted
time: 622ms
memory: 37436kb

input:

30 1000000001687
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 999999999991 13 317621530099 581606427561 21 5 7 27 6 459097506433 15 6 29 13 29 9 25 11 10 23 17 14 6 25 11 21 10 5 16 19

output:

1000000000571

result:

ok single line: '1000000000571'

Test #24:

score: 10
Accepted
time: 747ms
memory: 27736kb

input:

30 24647168232979
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 28 25 4 19 26 4 18 66088673790 8 137263321820 624543357354 491056742273 36762815810 79008946641 16 54849098117 18 417863353158 0 0 0 0 0 22 0 0 0 1 3 21

output:

1907436309137

result:

ok single line: '1907436309137'

Test #25:

score: 10
Accepted
time: 684ms
memory: 29532kb

input:

30 50595799989746
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 0 6 7 969584275447 0 509040037625 0 0 717396586408 0 0 0 2 0 0 18 0 0 0 508214812962

output:

impossible

result:

ok single line: 'impossible'

Test #26:

score: 10
Accepted
time: 748ms
memory: 35716kb

input:

30 8938647816682
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 27 841672536785 8 15 6 5 2 291166519149 19 673201071629 27 23 8 14 8 0 0 0 0 0 0 16 0 0 0 0 1 4 26 0 0

output:

1806040127724

result:

ok single line: '1806040127724'

Test #27:

score: 0
Wrong Answer
time: 646ms
memory: 22128kb

input:

30 783
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 437848852200 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 59617155335 820747192009 0

output:

impossible

result:

wrong answer 1st lines differ - expected: '437848852227', found: 'impossible'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #5:

0%

Subtask #8:

score: 0
Skipped

Dependency #6:

0%

Subtask #9:

score: 0
Skipped

Dependency #7:

0%

Subtask #10:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%