이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
static const int N = 200'010;
static int cnt[N];
static int test(int *a, int n)
{
fill(cnt, cnt+n, 0);
int pos = -1;
int mx = 1;
Loop (i,0,n) {
if (a[i] > n || 1 > a[i])
return -1;
if (a[i] > mx)
mx = a[i];
if (a[i] == 1)
pos = i;
cnt[a[i]-1]++;
}
if (cnt[0] != 1)
return -1;
Loop (i,0,mx-1)
if ((ll)cnt[i] * cnt[i] >= cnt[i+1])
return -1;
return pos;
}
static bool test_is_vector(void *add, int n)
{
cerr << "Hi" << endl;
ll *p = (ll *)add;
ll len = p[1] - p[0];
ll cap = p[2] - p[0];
if (len != n*sizeof(int))
{cerr << "Bye\n"; return 0;}
if (len > cap)
{cerr << "Bye\n"; return 0;}
if ((cap & -cap) != cap || cap == 0) // cap = 2^k
{cerr << "Bye\n"; return 0;}
{cerr << "Bye\n"; return 1;}
}
int find_best(int n)
{
vector<int> *dard = new vector<int>;
bool find_vec = 0;
for (void *add = dard;; add += 8) {
if (!test_is_vector(add, n))
continue;
find_vec = 1;
int **p = (int **)add;
cerr << p[0] << endl;
cerr << p[1] << endl;
cerr << p[2] << endl;
return -2;
int tmp = test(*(int **)add, n);
if (tmp != -1)
return tmp;
}
return -(1 + find_vec);
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'bool test_is_vector(void*, int)':
prize.cpp:41:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'long unsigned int' [-Wsign-compare]
41 | if (len != n*sizeof(int))
| ~~~~^~~~~~~~~~~~~~~~
prize.cpp: In function 'int find_best(int)':
prize.cpp:54:30: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
54 | for (void *add = dard;; add += 8) {
| ~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |