Submission #114969

# Submission time Handle Problem Language Result Execution time Memory
114969 2019-06-04T08:21:27 Z IVIosab Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

static int A[5000];
int a[5005];

void solve(int N) {
	int value = query(1, N);
	map<pair<int,int>,int> mp;
	for(int i=1;i<n-1;i++){
        int t=query(i,i+1);
        mp[{i,i+1}]=t;
	}
	for(int i=1;i<n-2;i++){
        int t=query(i,i+2);
        if(mp[{i,i+1}]+mp[{i+1,i+2}]==t){
            mp[{i,i+2]=1;
        }
	}
	int p1=1,p2=N;
	while(p2>p1){
        int v=query(p1,p2);
        if(v!=value){
            p2++;
            break;
        }
        p2--;
	}
	while(p1<p2){
        int v=query(p1,p2);
        if(v!=value){
            p1--;
            break;
        }
        p1++;
	}
	a[p1]=1;
	a[p2]=n;
	for(int i=p1-1;i>=0;i--){
        int t=mp[{i,i+1}];
        if(i==p1-1){
            a[i]=1+t;
        }
        else{
            if(mp[{i,i+2}]){
                if(a[i+1]>a[i+2]){
                    a[i]=a[i+1]+t;
                }
                else{
                    a[i]=a[i+1]-t;
                }
            }
            else{
                if(a[i+1]>a[i+2]){
                    a[i]=a[i+1]-t;
                }
                else{
                    a[i]=a[i+1]+t;
                }
            }
        }
	}
	if(p1!=p2-1){
        for(int i=p1+1;i<p2;i++){
            int t=mp[{i-1,i}];
            if(i==p1+1){
                a[i]=1+t;
            }
            else{
                if(mp[{i-2,i}]){
                    if(a[i-2]>a[i-1]){
                        a[i]=a[i-1]-t;
                    }
                    else{
                        a[i]=a[i-1]+t;
                    }
                }
                else{
                    if(a[i-2]>a[i-1]){
                        a[i]=a[i-1]+t;
                    }
                    else{
                        a[i]=a[i-1]-t;
                    }
                }
            }
        }
	}
	for(int i=p2+1;i<=n;i++){
        int t=mp[{i-1,i}];
        if(i==p2+1){
            a[i]=n-t;
        }
        else{
            if(mp[{i-2,i}]){
                if(a[i-2]>a[i-1]){
                    a[i]=a[i-1]-t;
                }
                else{
                    a[i]=a[i-1]+t;
                }
            }
            else{
                if(a[i-2]>a[i-1]){
                    a[i]=a[i-1]+t;
                }
                else{
                    a[i]=a[i-1]-t;
                }
            }
        }
	}
	for(int i=1;i<=n;i++){
        answer(i,a[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:11:16: error: 'n' was not declared in this scope
  for(int i=1;i<n-1;i++){
                ^
xylophone.cpp:15:16: error: 'n' was not declared in this scope
  for(int i=1;i<n-2;i++){
                ^
xylophone.cpp:18:22: error: expected '}' before ']' token
             mp[{i,i+2]=1;
                      ^
xylophone.cpp:39:8: error: 'n' was not declared in this scope
  a[p2]=n;
        ^
xylophone.cpp: At global scope:
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
 static int A[5000];
            ^