Submission #996089

# Submission time Handle Problem Language Result Execution time Memory
996089 2024-06-10T07:53:40 Z khanhtb Xylophone (JOI18_xylophone) C++17
47 / 100
2000 ms 848 KB
#include<bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<int>
#define vii vector<vi>
#define pint pair<int,int>
#define vpint vector<pint>
#define aint(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 1e4+8;
const ll buff = 1e5+1;
int a[N],dist[N][2];
bool check(int n){
    set<int> s;
    bool meetn = 0;
    for(int i = 1; i <= n; i++){
        s.insert(a[i]);
        if(a[i] == 1 && meetn) return 0;
        if(a[i] == n) meetn = 1;
    }
    if((ll)s.size() != n) return 0;
    if(*s.begin() != 1) return 0;
    if(*s.rbegin() != n) return 0;
    return 1;
}
void solve(int n){
    for(int i = 2; i <= n; i++){
        if(i > 1) dist[i][0] = query(i-1,i);
        if(i > 2) dist[i][1] = query(i-2,i);
    }
    for(int x = 1; x <= n; x++){
        a[1] = x;
        a[2] = x+dist[2][0];
        for(int i = 3; i <= n; i++){
            if(a[i-2] > a[i-1]){
                if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0];
                else a[i] = a[i-1]+dist[i][0];
            }
            else{
                if (a[i-1]-a[i-2]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0];
                else a[i] = a[i-1]-dist[i][0];
            }
        }
        if(check(n)) break;
        a[1] = x;
        a[2] = x-dist[2][0];
        for(int i = 3; i <= n; i++){
            if(a[i-2] > a[i-1]){
                if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0];
                else a[i] = a[i-1]+dist[i][0];
            }
            else{
                if (a[i-1]-a[i-2]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0];
                else a[i] = a[i-1]-dist[i][0];
            }
        }
        if(check(n)) break;
    }
    for(int i = 1; i <= n; i++) answer(i,a[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 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 444 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 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 444 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 18 ms 344 KB Output is correct
18 Correct 29 ms 444 KB Output is correct
19 Correct 96 ms 344 KB Output is correct
20 Correct 101 ms 600 KB Output is correct
21 Correct 100 ms 444 KB Output is correct
22 Correct 94 ms 452 KB Output is correct
23 Correct 10 ms 592 KB Output is correct
24 Correct 54 ms 444 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 95 ms 488 KB Output is correct
27 Correct 46 ms 452 KB Output is correct
28 Correct 36 ms 344 KB Output is correct
29 Correct 95 ms 600 KB Output is correct
30 Correct 27 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 2 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 444 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 444 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 18 ms 344 KB Output is correct
18 Correct 29 ms 444 KB Output is correct
19 Correct 96 ms 344 KB Output is correct
20 Correct 101 ms 600 KB Output is correct
21 Correct 100 ms 444 KB Output is correct
22 Correct 94 ms 452 KB Output is correct
23 Correct 10 ms 592 KB Output is correct
24 Correct 54 ms 444 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 95 ms 488 KB Output is correct
27 Correct 46 ms 452 KB Output is correct
28 Correct 36 ms 344 KB Output is correct
29 Correct 95 ms 600 KB Output is correct
30 Correct 27 ms 344 KB Output is correct
31 Correct 221 ms 600 KB Output is correct
32 Correct 1630 ms 600 KB Output is correct
33 Correct 1380 ms 700 KB Output is correct
34 Execution timed out 2695 ms 848 KB Time limit exceeded
35 Halted 0 ms 0 KB -