Submission #769644

# Submission time Handle Problem Language Result Execution time Memory
769644 2023-06-30T00:24:34 Z raysh07 Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 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;
            }
            
            vector <bool> st(n + 1, 0);
            for (int i = 1; i <= n; i++){
                st[ans[i]]++;
                if (st[ans[i]] > 1) 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;
            }
            
            vector <bool> st(n + 1, 0);
            for (int i = 1; i <= n; i++){
                st[ans[i]]++;
                if (st[ans[i]] > 1) good = false;
            }
            
            if (good){
                print();
                return;
            }
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:68:27: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
   68 |                 st[ans[i]]++;
      |                 ~~~~~~~~~~^~
xylophone.cpp:111:27: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
  111 |                 st[ans[i]]++;
      |                 ~~~~~~~~~~^~
xylophone.cpp: At global scope:
xylophone.cpp:5:23: warning: 'pos' defined but not used [-Wunused-variable]
    5 | static int ans[5001], pos[5001];
      |                       ^~~