이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 450;
vector<array<int, 3> > results;
int N;
bool cmp(array<int, 3> a, array<int, 3> b)
{
return ((a[0] + a[1]) > (b[0] + b[1]));
}
int DivideAndConquer(int l, int r)
{
if(l == 0 && r == N - 1)
{
int value1, value2;
if(results[0][0] != 0)
{
value1 = DivideAndConquer(l, results[0][2] - 1);
}
if(results[0][1] != 0)
{
value2 = DivideAndConquer(results[0][2] + 1, r);
}
if(results[0][0] == 0 && results[0][1] == 0)
{
return results[0][2];
}
if(value1 == -1)
{
return value2;
}
return value1;
}
int mid = (l + r) >> 1;
vector<int> reply = ask(mid);
if(reply[0] + reply[1] == 0)
{
return mid;
}
int value1, value2;
if(reply[0] != 0)
{
value1 = DivideAndConquer(l, mid - 1);
}
if(reply[1] != 0)
{
value2 = DivideAndConquer(mid + 1, r);
}
if(value1 == -1 && value2 == -1)
{
return -1;
}
if(value1 == -1)
{
return value2;
}
return value1;
}
int find_best(int n)
{
N = n;
int mid = n / 2;
vector<array<int, 3> > results;
for(int i = max(0, mid - MAXN / 2); i < min(n, mid + MAXN / 2 + 1); i++)
{
vector<int> reply = ask(i);
if(reply[0] + reply[1] == 0)
{
return i;
}
results.push_back({reply[0], reply[1], i});
}
sort(results.begin(), results.end(), cmp);
return DivideAndConquer(0, n - 1);
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int DivideAndConquer(int, int)':
prize.cpp:43:14: warning: 'value2' may be used uninitialized in this function [-Wmaybe-uninitialized]
43 | int value1, value2;
| ^~~~~~
prize.cpp:56:2: warning: 'value1' may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | if(value1 == -1)
| ^~
prize.cpp:18:15: warning: 'value2' may be used uninitialized in this function [-Wmaybe-uninitialized]
18 | int value1, value2;
| ^~~~~~
prize.cpp:31:3: warning: 'value1' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | if(value1 == -1)
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |