Submission #988449

# Submission time Handle Problem Language Result Execution time Memory
988449 2024-05-24T17:43:07 Z Zbyszek99 Xylophone (JOI18_xylophone) C++17
100 / 100
84 ms 1184 KB
#include <bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

int ans[5001];

void solve(int n)
{
    ans[1] = 0;
    ans[2] = query(1,2);
    int pop = ans[2];
    rep2(i,3,n)
    {
        int k1 = query(i-1,i);
        int k2 = query(i-2,i);
        if(pop + k1 == k2)
        {
            if(ans[i-2] < ans[i-1])
            {
                ans[i] = ans[i-1] + k1;
            }
            else
            {
                ans[i] = ans[i-1] - k1;
            }
        }
        else
        {
            if(ans[i-2] < ans[i-1])
            {
                ans[i] = ans[i-1] - k1;
            }
            else
            {
                ans[i] = ans[i-1] + k1;
            }
        }
        pop = k1;
    }
    pii mini = {1e9,0};
    pii maks = {-1e9,0};
    rep2(i,1,n)
    {
        mini = min(mini,{ans[i],i});
        maks = max(maks,{ans[i],i});
       // cout << ans[i] << " ans\n";
    }
    if(mini.ss > maks.ss)
    {
        rep2(i,1,n) ans[i] *= -1;
        maks.ff *= -1;
        mini.ff *= -1;
        swap(mini,maks);
    }
    int od = 1-mini.ff; 
  //  cout << od << " " << maks.ss << " " << mini.ss << " " << mini.ff << " mini\n";
    rep2(i,1,n) ans[i] += od;
    rep2(i,1,n) answer(i,ans[i]);

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 4 ms 440 KB Output is correct
18 Correct 6 ms 436 KB Output is correct
19 Correct 10 ms 596 KB Output is correct
20 Correct 12 ms 440 KB Output is correct
21 Correct 9 ms 440 KB Output is correct
22 Correct 8 ms 436 KB Output is correct
23 Correct 10 ms 444 KB Output is correct
24 Correct 9 ms 692 KB Output is correct
25 Correct 10 ms 692 KB Output is correct
26 Correct 10 ms 448 KB Output is correct
27 Correct 8 ms 692 KB Output is correct
28 Correct 13 ms 444 KB Output is correct
29 Correct 13 ms 640 KB Output is correct
30 Correct 8 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 4 ms 440 KB Output is correct
18 Correct 6 ms 436 KB Output is correct
19 Correct 10 ms 596 KB Output is correct
20 Correct 12 ms 440 KB Output is correct
21 Correct 9 ms 440 KB Output is correct
22 Correct 8 ms 436 KB Output is correct
23 Correct 10 ms 444 KB Output is correct
24 Correct 9 ms 692 KB Output is correct
25 Correct 10 ms 692 KB Output is correct
26 Correct 10 ms 448 KB Output is correct
27 Correct 8 ms 692 KB Output is correct
28 Correct 13 ms 444 KB Output is correct
29 Correct 13 ms 640 KB Output is correct
30 Correct 8 ms 444 KB Output is correct
31 Correct 17 ms 448 KB Output is correct
32 Correct 35 ms 684 KB Output is correct
33 Correct 40 ms 440 KB Output is correct
34 Correct 37 ms 928 KB Output is correct
35 Correct 61 ms 940 KB Output is correct
36 Correct 44 ms 692 KB Output is correct
37 Correct 48 ms 448 KB Output is correct
38 Correct 45 ms 948 KB Output is correct
39 Correct 39 ms 688 KB Output is correct
40 Correct 41 ms 696 KB Output is correct
41 Correct 39 ms 696 KB Output is correct
42 Correct 42 ms 704 KB Output is correct
43 Correct 55 ms 692 KB Output is correct
44 Correct 44 ms 604 KB Output is correct
45 Correct 42 ms 680 KB Output is correct
46 Correct 50 ms 928 KB Output is correct
47 Correct 84 ms 676 KB Output is correct
48 Correct 47 ms 952 KB Output is correct
49 Correct 43 ms 540 KB Output is correct
50 Correct 45 ms 948 KB Output is correct
51 Correct 45 ms 684 KB Output is correct
52 Correct 39 ms 956 KB Output is correct
53 Correct 59 ms 928 KB Output is correct
54 Correct 43 ms 948 KB Output is correct
55 Correct 46 ms 696 KB Output is correct
56 Correct 57 ms 688 KB Output is correct
57 Correct 61 ms 692 KB Output is correct
58 Correct 53 ms 1184 KB Output is correct
59 Correct 45 ms 924 KB Output is correct
60 Correct 39 ms 1184 KB Output is correct