QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389019#362. SparklersRafi220 1ms5608kbC++141.9kb2024-04-13 23:35:512024-04-13 23:35:53

Judging History

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

  • [2024-04-13 23:35:53]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5608kb
  • [2024-04-13 23:35:51]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
int mod=1000000007;
int mod1=998244353;

const int N=100007;

//bool DP[N][N];

int a[N];
int b[N];
int c[N];
int n;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k,t;
    cin>>n>>k>>t;
    for(int i=1;i<=n;i++) cin>>a[i];
    int X=k-1,Y=n-k;
    for(int i=1;i<=k-1;i++) b[i]=-(a[k-i+1]-a[k-i]);
    for(int i=1;i<=n-k;i++) c[i]=-(a[k+i]-a[i+k-1]);
    int l=0,r=1000000000,sr,ans=inf; 
    while(l<=r)
    {
        sr=(l+r)/2;
        if(sr*t>1000000000)
        {
            ans=sr;
            r=sr-1;
            continue;
        }
        for(int i=1;i<=X;i++) b[i]+=2*sr*t;
        for(int i=1;i<=Y;i++) c[i]+=2*sr*t;
        
        
        int x=0,y=0,S=0;
        while(true)
        {
			bool is=0;
			int s=0;
			for(int i=x+1;i<=X;i++)
			{
				s+=b[i];
				if(s+S<0) break;
				if(s>0)
				{
					is=1;
					S+=s;
					x=i;
					break;
				}
			}
			s=0;
			for(int i=y+1;i<=Y;i++)
			{
				s+=c[i];
				if(s+S<0) break;
				if(s>0)
				{
					is=1;
					S+=s;
					y=i;
					break;
				}
			}
			if(!is) break;
		}
		int mnx=0,sx=0;
		for(int i=x+1;i<=X;i++) 
		{
			sx+=b[i];
			mnx=min(mnx,sx);
		}
		int mny=0,sy=0;
		for(int i=y+1;i<=Y;i++) 
		{
			sy+=c[i];
			mny=min(mny,sy);
		}
		bool ok=0;
		if(S+mnx>=0&&S+sx+mny>=0) ok=1;
		if(S+mny>=0&&S+sy+mnx>=0) ok=1;
        if(ok)
        {
            ans=sr;
            r=sr-1;
        }
        else l=sr+1;
        for(int i=1;i<=X;i++) b[i]-=2*sr*t;
        for(int i=1;i<=Y;i++) c[i]-=2*sr*t;
    }
    cout<<ans;




    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 3652kb

input:

10 9 2
0
1117660
2284171
3390084
3568342
4222750
5180454
6186411
6360445
6519656

output:

181102

result:

ok single line: '181102'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

3 2 1
0
368765
1493921

output:

373481

result:

ok single line: '373481'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5608kb

input:

9 8 4
0
1970871
2488111
3723411
5581758
7596649
8984403
9989980
10451978

output:

168215

result:

ok single line: '168215'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

20 18 1
0
462590
635597
1653028
1731039
2632280
2993419
3958675
4824859
4923991
5874922
6721441
7856685
8109245
8187843
8916119
9662776
10617094
11598860
11759660

output:

477159

result:

ok single line: '477159'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

20 19 1
0
16714
600564
1738550
2860146
3233681
3470376
3511936
4127893
5089595
5771375
5923055
6712524
7645593
7839588
7939256
8270988
8365309
8565641
8764207

output:

242986

result:

ok single line: '242986'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

20 19 1
0
360130
416278
565928
1137578
1907790
2582414
3700996
4219574
4315031
4708493
5703532
6750886
7008779
7292334
7354499
8425871
8951795
9692673
9903623

output:

318641

result:

ok single line: '318641'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

20 3 1
0
497352
601758
1175884
1245741
1585758
1746236
2367513
2732420
2739779
3351827
3525038
4143423
4321819
5000239
5107430
5312137
5958753
6370846
6513352

output:

173188

result:

ok single line: '173188'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

20 7 1
0
416112
1276119
1776741
1971354
3051516
3964787
4752968
5114629
5456785
5783476
6450733
7492246
8117636
8726706
9380206
9424138
9680412
10381694
11143315

output:

394091

result:

ok single line: '394091'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

20 17 1
0
418275
1609767
2826602
4126911
5045015
5863900
5903447
6048863
6976925
7826789
8397913
8479522
9312544
9618482
9751692
10846799
12065875
12985857
14274374

output:

547554

result:

ok single line: '547554'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

20 5 1
0
636862
675532
1067405
2149723
2433765
3448119
4927611
5075453
6024114
6742671
7335495
8053680
9461089
10479891
11154362
11537902
11790723
12326305
13349359

output:

374282

result:

ok single line: '374282'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

20 9 1
0
253324
316843
568058
673961
952771
1319011
1398887
1748830
1895752
2246598
2269716
2344119
2451418
2690003
2985338
3065614
3143399
3495892
3568533

output:

124217

result:

ok single line: '124217'

Test #12:

score: -20
Wrong Answer
time: 0ms
memory: 3648kb

input:

20 11 1
0
51952
61227
162819
249127
306399
334761
382780
449122
509397
542856
610609
616723
637063
646745
686393
770737
862074
908186
946759

output:

25356

result:

wrong answer 1st lines differ - expected: '25317', found: '25356'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%