답안 #66149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66149 2018-08-09T22:10:50 Z reality Xylophone (JOI18_xylophone) C++17
컴파일 오류
0 ms 0 KB
#include "xylophone.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}

const int N = 1e6 + 5;

int s[N];

int d1[N];
int d2[N];

void detect_pitch(int NN) {
	int n = NN;
	for (int i = 0;i + 1 < n;++i)
		d1[i] = ask(i,i + 1);
	for (int i = 0;i + 2 < n;++i)
		d2[i] = ask(i,i + 2);
	for (int sg = 0;sg < 2;++sg) {
			s[0] = 0;
			int shit = sg;
			for (int i = 1;i < n;++i) {
				if (shit)
					s[i] = s[i - 1] - d1[i - 1];
				else
					s[i] = s[i - 1] + d1[i - 1];
				if (d2[i - 1] != d1[i - 1] + d1[i]) 
					shit ^= 1;
			}
			int mn = min_element(s,s + n) - s;
			int mx = max_element(s,s + n) - s;
			const int val = s[mn];
			for (int i = 0;i < n;++i)
				s[i] -= val;
			int ok = (mn < mx);
			for (int i = 0;i < n;++i)
				ok &= 0 <= s[i] && s[i] < n;
			set < int > ss;
			for (int i = 0;i < n;++i)
				ss.insert(s[i]);
			ok &= ss.size() == n;
			if (ok) {
				break;
			} else {
				assert(sg == 0);
			}
		}
	for (int i = 0;i < n;++i)
		answer(i,s[i]);
}

Compilation message

xylophone.cpp: In function 'void detect_pitch(int)':
xylophone.cpp:30:11: error: 'ask' was not declared in this scope
   d1[i] = ask(i,i + 1);
           ^~~
xylophone.cpp:32:11: error: 'ask' was not declared in this scope
   d2[i] = ask(i,i + 2);
           ^~~
xylophone.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    ok &= ss.size() == n;
          ~~~~~~~~~~^~~~