이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int N, K, M, nr, ans[1000009], a[1000009], stk[1000009];
bool type[1000009];
void print (int val, int &needToAdd)
{
if (needToAdd == 0 || val == 0)
{
printf ("%d ", val);
return ;
}
needToAdd --;
print (val - 1, needToAdd);
print (val - 1, needToAdd);
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d", &N, &K);
for (int i=1; i<=N; i++)
scanf ("%d", &a[i]);
ans[1] = a[1], type[1] = 1;
stk[1] = a[1], nr = 1, M = 1;
for (int i=2; i<=N; i++)
{
while (a[i] > stk[nr])
{
ans[++M] = stk[nr];
stk[nr + 1] = stk[nr], nr ++;
while (nr >= 2 && stk[nr] == stk[nr - 1])
nr --, stk[nr] ++;
}
if (a[i] <= stk[nr])
{
ans[++M] = a[i], type[M] = 1;
if (a[i] < stk[nr]) stk[++nr] = a[i];
else
{
stk[++nr] = a[i];
while (nr >= 2 && stk[nr] == stk[nr - 1])
nr --, stk[nr] ++;
}
continue;
}
}
while (nr > 1 || stk[1] < 30)
{
ans[++M] = stk[nr];
stk[nr + 1] = stk[nr], nr ++;
while (nr >= 2 && stk[nr] == stk[nr - 1])
nr --, stk[nr] ++;
}
int needToAdd = K - (M - N);
for (int i=1; i<=M; i++)
if (type[i] == 1) printf ("%d ", ans[i]);
else
if (type[i] == 0) print (ans[i], needToAdd);
printf ("\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &N, &K);
~~~~~~^~~~~~~~~~~~~~~~~
zalmoxis.cpp:27:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &a[i]);
~~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |