Submission #851435

# Submission time Handle Problem Language Result Execution time Memory
851435 2023-09-19T18:33:24 Z Andrei Xylophone (JOI18_xylophone) C++17
47 / 100
20 ms 1208 KB
#include <bits/stdc++.h>

#include "xylophone.h"

using namespace std;

int a[5005];
int b[1005];

int diff1[5005];
int diff2[5005];

bool same[5005];

bool bigger[5005];

/*
int query(int s,int t);
void answer(int i,int v);
*/ 

void solve(int n)
{
    if(n==2)
    {
        answer(1,1);
        answer(2,2);
        return;
    }

    for(int i=1; i<n; i++)
        diff1[i]=query(i,i+1);
    for(int i=1; i<n-1; i++)
        diff2[i]=query(i,i+2);

    for(int i=1; i<n-1; i++)
    {
        if(diff2[i]==diff1[i]+diff1[i+1])
            same[i]=1;
        else
            same[i]=0;
    }

    int sign=1;
    a[1]=0;
    for(int i=1; i<n; i++)
    {
        a[i+1]=a[i]+sign*diff1[i];
        if(i+1<n && same[i]==0)
            sign*=-1;
    }

    sign=-1;
    b[1]=0;
    for(int i=1; i<n; i++)
    {
        b[i+1]=b[i]+sign*diff1[i];
        if(i+1<n && same[i]==0)
            sign*=-1;
    }

    /*
    for(int i=1; i<=n; i++)
        cout<<A[i]<<" ";
    cout<<"\n";
    for(int i=1; i<=n; i++)
        cout<<B[i]<<" ";
    cout<<"\n";
    */

    int minA=n;
    for(int i=1; i<=n; i++)
        minA=min(minA,a[i]);

    int minB=n;
    for(int i=1; i<=n; i++)
        minB=min(minB,b[i]);

    int pminA,pminB;
    for(int i=1; i<=n; i++)
    {
        if(a[i]==minA)
            pminA=i;
        if(b[i]==minB)
            pminB=i;
    }

    if(pminB<pminA)
    {
        for(int i=1; i<=n; i++)
            swap(a[i],b[i]);
        swap(minA,minB);
    }

    for(int i=1; i<=n; i++)
        answer(i,a[i]-minA+1);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:88:5: warning: 'pminB' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |     if(pminB<pminA)
      |     ^~
xylophone.cpp:88:5: warning: 'pminA' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 2 ms 864 KB Output is correct
5 Correct 2 ms 696 KB Output is correct
6 Correct 1 ms 700 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 696 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 1 ms 696 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 2 ms 864 KB Output is correct
5 Correct 2 ms 696 KB Output is correct
6 Correct 1 ms 700 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 696 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 1 ms 696 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 4 ms 696 KB Output is correct
18 Correct 8 ms 856 KB Output is correct
19 Correct 7 ms 696 KB Output is correct
20 Correct 8 ms 700 KB Output is correct
21 Correct 9 ms 952 KB Output is correct
22 Correct 7 ms 948 KB Output is correct
23 Correct 8 ms 700 KB Output is correct
24 Correct 10 ms 960 KB Output is correct
25 Correct 9 ms 692 KB Output is correct
26 Correct 9 ms 696 KB Output is correct
27 Correct 9 ms 1208 KB Output is correct
28 Correct 9 ms 692 KB Output is correct
29 Correct 9 ms 696 KB Output is correct
30 Correct 10 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 436 KB Output is correct
4 Correct 2 ms 864 KB Output is correct
5 Correct 2 ms 696 KB Output is correct
6 Correct 1 ms 700 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 440 KB Output is correct
9 Correct 1 ms 696 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
11 Correct 1 ms 440 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 1 ms 696 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 1 ms 440 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 4 ms 696 KB Output is correct
18 Correct 8 ms 856 KB Output is correct
19 Correct 7 ms 696 KB Output is correct
20 Correct 8 ms 700 KB Output is correct
21 Correct 9 ms 952 KB Output is correct
22 Correct 7 ms 948 KB Output is correct
23 Correct 8 ms 700 KB Output is correct
24 Correct 10 ms 960 KB Output is correct
25 Correct 9 ms 692 KB Output is correct
26 Correct 9 ms 696 KB Output is correct
27 Correct 9 ms 1208 KB Output is correct
28 Correct 9 ms 692 KB Output is correct
29 Correct 9 ms 696 KB Output is correct
30 Correct 10 ms 700 KB Output is correct
31 Runtime error 20 ms 692 KB Execution killed with signal 13
32 Halted 0 ms 0 KB -