Submission #769643

# Submission time Handle Problem Language Result Execution time Memory
769643 2023-06-30T00:23:31 Z raysh07 Xylophone (JOI18_xylophone) C++17
47 / 100
2000 ms 580 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

static int ans[5001], pos[5001];
static int a[5001], b[5001];
static int n;

void print(){
    for (int i = 1; i <= n; i++){
      //  cout << ans[i] << " ";
        answer(i, ans[i]);
    }
   // cout << "\n";
}

void solve(int nn) {
    n = nn;

// 	int value = query(1, N);

// 	for(int i = 1; i <= N; i++) {
// 		answer(i, i);
// 	}
    
    for (int i = 1; i < n; i++){
        a[i] = query(i, i + 1);
    }
    for (int i = 1; i < n - 1; i++){
        b[i] = query(i, i + 2);
    }
    
    for (int i = 1; i <= n; i++){
        ans[1] = i;
        if (i + a[1] <= n){
            ans[2] = i + a[1];
            
            bool seen = false;
            bool good = true;
            
            for (int j = 3; j <= n; j++){
                if (a[j - 2] + a[j - 1] == b[j - 2]) {
                    if (ans[j - 1] > ans[j - 2]){
                        ans[j] = ans[j - 1] + a[j - 1];
                    } else {
                        ans[j] = ans[j - 1] - a[j - 1];
                    }
                } else {
                    if (ans[j - 1] > ans[j - 2]){
                        ans[j] = ans[j - 1] - a[j - 1];
                    } else {
                        ans[j] = ans[j - 1] + a[j - 1];
                    }
                }
                
                if (ans[j] < 1 || ans[j] > n){
                    good = false;
                }
            }
            
            for (int j = 1; j <= n; j++){
                if (ans[j] == 1) seen = true;
                if (ans[j] == n && !seen) good = false;
            }
            
            set <int> st;
            for (int j = 1; j <= n; j++) st.insert(ans[j]);
            
            if (st.size() != n) good = false;
            
            if (good){
                print();
                return;
            }
        }
        
        if (i - a[1] >= 1){
            ans[2] = i - a[1];
            
            bool seen = false;
            bool good = true;
            
            for (int j = 3; j <= n; j++){
                if (a[j - 2] + a[j - 1] == b[j - 2]) {
                    if (ans[j - 1] > ans[j - 2]){
                        ans[j] = ans[j - 1] + a[j - 1];
                    } else {
                        ans[j] = ans[j - 1] - a[j - 1];
                    }
                } else {
                    if (ans[j - 1] > ans[j - 2]){
                        ans[j] = ans[j - 1] - a[j - 1];
                    } else {
                        ans[j] = ans[j - 1] + a[j - 1];
                    }
                }
                
                if (ans[j] < 1 || ans[j] > n){
                    good = false;
                }
            }
            
            for (int j = 1; j <= n; j++){
                if (ans[j] == 1) seen = true;
                if (ans[j] == n && !seen) good = false;
            }
            
            set <int> st;
            for (int j = 1; j <= n; j++) st.insert(ans[j]);
            
            if (st.size() != n) good = false;
            
            if (good){
                print();
                return;
            }
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:69:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |             if (st.size() != n) good = false;
      |                 ~~~~~~~~~~^~~~
xylophone.cpp:111:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  111 |             if (st.size() != n) good = false;
      |                 ~~~~~~~~~~^~~~
xylophone.cpp: At global scope:
xylophone.cpp:5:23: warning: 'pos' defined but not used [-Wunused-variable]
    5 | static int ans[5001], pos[5001];
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 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 2 ms 308 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 2 ms 304 KB Output is correct
11 Correct 2 ms 304 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 2 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 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 2 ms 308 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 2 ms 304 KB Output is correct
11 Correct 2 ms 304 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 2 ms 300 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 12 ms 208 KB Output is correct
18 Correct 27 ms 308 KB Output is correct
19 Correct 119 ms 288 KB Output is correct
20 Correct 161 ms 348 KB Output is correct
21 Correct 40 ms 360 KB Output is correct
22 Correct 145 ms 304 KB Output is correct
23 Correct 12 ms 312 KB Output is correct
24 Correct 65 ms 316 KB Output is correct
25 Correct 17 ms 292 KB Output is correct
26 Correct 141 ms 320 KB Output is correct
27 Correct 43 ms 304 KB Output is correct
28 Correct 29 ms 304 KB Output is correct
29 Correct 122 ms 312 KB Output is correct
30 Correct 27 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 0 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 2 ms 308 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 304 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 2 ms 304 KB Output is correct
11 Correct 2 ms 304 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 2 ms 300 KB Output is correct
16 Correct 5 ms 208 KB Output is correct
17 Correct 12 ms 208 KB Output is correct
18 Correct 27 ms 308 KB Output is correct
19 Correct 119 ms 288 KB Output is correct
20 Correct 161 ms 348 KB Output is correct
21 Correct 40 ms 360 KB Output is correct
22 Correct 145 ms 304 KB Output is correct
23 Correct 12 ms 312 KB Output is correct
24 Correct 65 ms 316 KB Output is correct
25 Correct 17 ms 292 KB Output is correct
26 Correct 141 ms 320 KB Output is correct
27 Correct 43 ms 304 KB Output is correct
28 Correct 29 ms 304 KB Output is correct
29 Correct 122 ms 312 KB Output is correct
30 Correct 27 ms 308 KB Output is correct
31 Correct 164 ms 420 KB Output is correct
32 Correct 1314 ms 472 KB Output is correct
33 Correct 991 ms 544 KB Output is correct
34 Execution timed out 2224 ms 580 KB Time limit exceeded
35 Halted 0 ms 0 KB -