이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
void solve(int N) {
int n = N;
vector <int> last;
last.pb(0);
last.pb(query(1, 2));
for(int i = 3; i <= n; i++){
int x = query(i - 1, i);
int y = query(i - 2, i);
int l = last.back() / (abs(last.back()));
if(y == x + abs(last.back())) last.pb(x * l);
else last.pb(-x * l);
}
map<int, int> used;
used[0] = true;
int pref = 0;
int ind;
for(int i = 1; i < last.size(); i++){
pref += last[i];
if(used[pref - (n - 1)]){
ind = i;
break;
}
if(used[pref - (1 - n)]){
ind = i;
break;
}
used[pref] = true;
}
if(last[ind] < 0){
for(int i = 0; i < last.size(); i++) last[i] *= (-1);
}
// answer(ind + 1, n);
int a[n + 1];
a[ind + 1] = n;
for(int i = ind; i >= 0; i--){
int x = last[i];
a[i] = a[i + 1] - x;
// answer(i, a[i]);
}
for(int i = ind + 2; i <= n; i++){
int x = last[i - 1];
a[i] = a[i - 1] + x;
// answer(i, a[i]);
}
for(int i = 1; i <= n; i++) answer(i, a[i]);
}
컴파일 시 표준 에러 (stderr) 메시지
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 1; i < last.size(); i++){
| ~~^~~~~~~~~~~~~
xylophone.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < last.size(); i++) last[i] *= (-1);
| ~~^~~~~~~~~~~~~
xylophone.cpp:43:16: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
43 | if(last[ind] < 0){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |