Submission #590466

# Submission time Handle Problem Language Result Execution time Memory
590466 2022-07-06T01:20:04 Z tamthegod Xylophone (JOI18_xylophone) C++14
47 / 100
73 ms 328 KB
#include<bits/stdc++.h>
#include "xylophone.h"

#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 5000 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int res[maxN];
void solve(int n)
{
    int low = 1, high = n, mid;
    while(low <= high)
    {
        mid = (low + high) / 2;
        if(query(mid, n) == n - 1) low = mid + 1;
        else high = mid -1;
    }
    low--;
    res[low] = 1;
    //cout << query(1, 2);exit(0);
    if(low > 1)
    {
        res[low - 1] = 1 + query(low - 1, low);
    }
    if(low < n) res[low + 1] = 1 + query(low, low + 1);
    for(int i=low-2; i>=1; i--)
    {
        int val1 = query(i, i + 1);
        int val2 = query(i, i + 2);
        if(res[i + 1] > res[i + 2])
        {
            if(res[i + 1] - res[i + 2] == val2)
            {
                res[i] = res[i + 1] - val1;
            }
            else
            {
                int val = res[i + 2] + val2;
                if(val - res[i + 1] == val1) res[i] = val;
                else res[i] = res[i + 1] - val2;
            }
        }
        else
        {
            if(res[i + 2] - res[i + 1] == val2)
            {
                res[i] = res[i + 1] + val1;
            }
            else
            {
                int val = res[i + 2] - val2;
                if(res[i + 1] - val == val1) res[i] = val;
                else res[i] = res[i + 1] + val2;
            }
        }
    }
    for(int i=low+2; i<=n; i++)
    {
        int val1 = query(i - 1, i);
        int val2 = query(i - 2, i);
        if(res[i - 1] > res[i - 2])
        {
            if(res[i - 1] - res[i - 2] == val2)
            {
                res[i] = res[i - 1] - val1;
            }
            else
            {
                int val = res[i - 2] + val2;
                if(val - res[i - 1] == val1) res[i] = val;
                else res[i] = res[i - 1] - val2;
            }
        }
        else
        {
            if(res[i - 2] - res[i - 1] == val2)
            {
                res[i] = res[i - 1] + val1;
            }
            else
            {
                int val = res[i - 2] - val2;
                if(res[i - 1] - val == val1) res[i] = val;
                else res[i] = res[i - 1] + val2;
            }
        }
    }
    for(int i=1; i<=n; i++) answer(i, res[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 3 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 3 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 13 ms 208 KB Output is correct
18 Correct 14 ms 296 KB Output is correct
19 Correct 14 ms 208 KB Output is correct
20 Correct 21 ms 208 KB Output is correct
21 Correct 16 ms 308 KB Output is correct
22 Correct 17 ms 328 KB Output is correct
23 Correct 13 ms 288 KB Output is correct
24 Correct 20 ms 292 KB Output is correct
25 Correct 15 ms 304 KB Output is correct
26 Correct 15 ms 208 KB Output is correct
27 Correct 14 ms 292 KB Output is correct
28 Correct 13 ms 208 KB Output is correct
29 Correct 20 ms 292 KB Output is correct
30 Correct 18 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 3 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 4 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 13 ms 208 KB Output is correct
18 Correct 14 ms 296 KB Output is correct
19 Correct 14 ms 208 KB Output is correct
20 Correct 21 ms 208 KB Output is correct
21 Correct 16 ms 308 KB Output is correct
22 Correct 17 ms 328 KB Output is correct
23 Correct 13 ms 288 KB Output is correct
24 Correct 20 ms 292 KB Output is correct
25 Correct 15 ms 304 KB Output is correct
26 Correct 15 ms 208 KB Output is correct
27 Correct 14 ms 292 KB Output is correct
28 Correct 13 ms 208 KB Output is correct
29 Correct 20 ms 292 KB Output is correct
30 Correct 18 ms 288 KB Output is correct
31 Correct 36 ms 288 KB Output is correct
32 Correct 63 ms 304 KB Output is correct
33 Correct 70 ms 300 KB Output is correct
34 Incorrect 73 ms 296 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -