QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#195171#5150. Alternating Algorithmkevinshan#WA 1ms3824kbC++141.3kb2023-10-01 01:40:032023-10-01 01:40:04

Judging History

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

  • [2023-10-01 01:40:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3824kb
  • [2023-10-01 01:40:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
int xm[4] = {-1, 1, 0, 0};
int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll POW = 9973;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n;
    vector<pair<int, int>> ar;
    n++;
    for(int i=0; i<n; i++){
        pair<int, int> p = {0,i};
        cin>>p.f;
        ar.pb(p);
    }
    sort(all(ar));
    // for(auto p:ar){
    //     cout<<p.f<<" "<<p.s<<"\n";
    // }
    int ans = 0;
    for(int i=0; i<n; i++){
        if(ar[i].s < i){
            // 01, 23, ...
            if(ar[i].s % 2 == 0){
                ans = max(ans, abs(ar[i].s-i));
            }
            else ans = max(ans, abs(ar[i].s-i) + 1);
        }
        else if(ar[i].s > i){
            if(ar[i].s % 2 ==1){
                ans = max(ans, abs(ar[i].s-i));
            }
            else ans = max(ans, abs(ar[i].s-i) + 1);
        }
    }
    cout<<ans;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3600kb

input:

3
8 13 4 10

output:

3

result:

ok single line: '3'

Test #2:

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

input:

5
13 12 14 10 14 12

output:

3

result:

ok single line: '3'

Test #3:

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

input:

2
2 2 1

output:

3

result:

ok single line: '3'

Test #4:

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

input:

1
300172042 474444146

output:

0

result:

ok single line: '0'

Test #5:

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

input:

1
636357447 557539481

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2
139715426 368724097 417561009

output:

0

result:

ok single line: '0'

Test #7:

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

input:

2
77784868 542697475 509604021

output:

2

result:

ok single line: '2'

Test #8:

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

input:

2
698395658 71848686 699775597

output:

1

result:

ok single line: '1'

Test #9:

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

input:

2
487635147 571273621 442673389

output:

3

result:

ok single line: '3'

Test #10:

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

input:

2
502022170 254766224 258867503

output:

2

result:

ok single line: '2'

Test #11:

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

input:

2
783651505 271735448 154090385

output:

3

result:

ok single line: '3'

Test #12:

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

input:

3
423187900 701340783 708457090 788989478

output:

0

result:

ok single line: '0'

Test #13:

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

input:

3
172068101 507957913 237246316 805323765

output:

2

result:

ok single line: '2'

Test #14:

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

input:

3
309846480 218704879 536482379 754210806

output:

1

result:

ok single line: '1'

Test #15:

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

input:

3
150235215 485036833 52089968 645641645

output:

3

result:

ok single line: '3'

Test #16:

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

input:

3
735389981 669677621 733676260 858050940

output:

2

result:

ok single line: '2'

Test #17:

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

input:

3
635103474 551413670 85269704 730878535

output:

3

result:

ok single line: '3'

Test #18:

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

input:

3
287528440 314452762 846234936 452787633

output:

1

result:

ok single line: '1'

Test #19:

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

input:

3
276069955 969481471 992185356 536479156

output:

2

result:

ok single line: '2'

Test #20:

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

input:

3
225096493 88165689 415816372 360778803

output:

1

result:

ok single line: '1'

Test #21:

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

input:

3
651934487 760368054 975264908 206290402

output:

3

result:

ok single line: '3'

Test #22:

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

input:

3
668819975 16012633 798541220 258404088

output:

2

result:

ok single line: '2'

Test #23:

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

input:

3
303955151 276719749 324951113 63908344

output:

3

result:

ok single line: '3'

Test #24:

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

input:

3
419862649 709195111 424612582 548104611

output:

3

result:

ok single line: '3'

Test #25:

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

input:

3
46436854 762650424 543885894 63420906

output:

3

result:

ok single line: '3'

Test #26:

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

input:

3
663885616 817966829 428282021 750799481

output:

3

result:

ok single line: '3'

Test #27:

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

input:

3
453815838 784866392 626401113 33629018

output:

3

result:

ok single line: '3'

Test #28:

score: -100
Wrong Answer
time: 0ms
memory: 3596kb

input:

3
612031283 905623341 296446821 317142883

output:

3

result:

wrong answer 1st lines differ - expected: '4', found: '3'