Submission #996070

# Submission time Handle Problem Language Result Execution time Memory
996070 2024-06-10T07:43:52 Z anHiep Xylophone (JOI18_xylophone) C++17
0 / 100
2 ms 2392 KB
#include "xylophone.h"
#include<bits/stdc++.h>

using namespace std;

static int a[5005];
static int d[5005][5005]; 

void solve(int n) {
	int dis = query(1, 2);
    for(int i=3; i<=n; i++) {
        d[i - 2][i] = query(i - 2, i);
        d[i - 1][i] = query(i - 1, i);
    }
    for(int i=1; i<=n; i++) {
        a[1] = i;
        for(int k=-1; k<=1; k+=2) {
            set<int> s;
            a[2] = a[1] + k*dis;
            s.insert(a[1]);
            s.insert(a[2]);
            for(int j=3; j<=n; j++) {
                int cal = max(a[j - 1], a[j - 2]) - min(a[j - 1], a[j - 2]);
                if(d[j - 2][j] == cal) {
                    if(a[j - 1] > a[j - 2]) a[j] = a[j - 1] - d[j - 1][j];
                    else a[j] = a[j - 1] + d[j - 1][j];
                }
                else {
                    if(a[j - 1] + d[j - 1][j] - min(a[j - 2], a[j - 1]) == d[j - 2][j]) a[j] = a[j - 1] + d[j - 1][j];
                    if(max(a[j - 2], a[j - 1]) - (a[j - 1] - d[j - 1][j]) == d[j - 2][j]) a[j] = a[j - 1] - d[j - 1][j];
                }
                s.insert(a[j]);
            }
            if(s.size() == n && *s.begin() == 1 && *s.rbegin() == n) {
                for(int j=1; j<=n; j++) answer(j, a[j]);
                return;
            }
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:34:25: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |             if(s.size() == n && *s.begin() == 1 && *s.rbegin() == n) {
      |                ~~~~~~~~~^~~~
# 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Incorrect 2 ms 2392 KB Wrong Answer [7]
8 Halted 0 ms 0 KB -
# 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Incorrect 2 ms 2392 KB Wrong Answer [7]
8 Halted 0 ms 0 KB -
# 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 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Incorrect 2 ms 2392 KB Wrong Answer [7]
8 Halted 0 ms 0 KB -