제출 #255761

#제출 시각아이디문제언어결과실행 시간메모리
255761IgorIXylophone (JOI18_xylophone)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; int n; #ifdef LOCAL int query(int l, int r) { cout << "? " << l << " " << r << endl; int x; cin >> x; return x; } void answer(int i, int x) { cout << "! " << i << " " << x << endl; } #endif // LOCAL int okay(vector<int> q) { int pos1 = 0, posn = 0; vector<int> cnt(n + 1); for (int i = 1; i <= n; i++) { if (q[i] < 1 || q[i] > n) return 0; cnt[q[i]]++; if (cnt[q[i]] == 2) return 0; if (q[i] == 1) pos1 = i; if (q[i] == n) posn = i; } return pos1 < posn; } void solve(int n0) { n = n0; vector<int> a(n), b(n); for (int i = 1; i + 1 <= n; i++) { a[i] = query(i, i + 1); } for (int i = 1; i + 2 <= n; i++) { b[i] = query(i, i + 2); } vector<int> dir(n); dir[1] = 1; for (int i = 1; i + 2 <= n; i++) { if (b[i] == a[i] + a[i + 1]) dir[i + 1] = dir[i]; else dir[i + 1] = dir[i] * (-1); } vector<vector<int> > ans; for (int i = 1; i <= n; i++) { vector<int> q(n + 1); q[1] = i; q[2] = dir[1] * a[1] + q[1]; for (int j = 3; j <= n; j++) { q[j] = q[j - 1] + dir[j - 1] * a[j - 1]; } if (okay(q)) ans.push_back(q); } for (int i = 1; i < n; i++) dir[i] *= -1; for (int i = 1; i <= n; i++) { vector<int> q(n + 1); q[1] = i; q[2] = dir[1] * a[1] + q[1]; for (int j = 3; j <= n; j++) { q[j] = q[j - 1] + dir[j - 1] * a[j - 1]; } if (okay(q)) ans.push_back(q); } for (auto e : ans) { for (int i = 1; i <= n; i++) { answer(i, e[i]); } } } #ifdef LOCAL int main() { int n; cin >> n; solve(n); } #endif // LOCAL

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:47:16: error: 'query' was not declared in this scope
         a[i] = query(i, i + 1);
                ^~~~~
xylophone.cpp:51:16: error: 'query' was not declared in this scope
         b[i] = query(i, i + 2);
                ^~~~~
xylophone.cpp:88:13: error: 'answer' was not declared in this scope
             answer(i, e[i]);
             ^~~~~~
xylophone.cpp:88:13: note: suggested alternative: 'ans'
             answer(i, e[i]);
             ^~~~~~
             ans