제출 #94415

#제출 시각아이디문제언어결과실행 시간메모리
94415KastandaMoney (IZhO17_money)C++11
100 / 100
264 ms18808 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, cnt, A[N], C[N], nxt[N];
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &A[i]), C[A[i]] ++;
    C[N - 1] ++;
    for (int i = N - 2; i; i--)
    {
        nxt[i] = i + 1;
        while (!C[nxt[i]])
            nxt[i] = nxt[nxt[i]];
    }
    for (int i = n; i;)
    {
        int used = 0;
        int l = i - 1;
        while (l)
        {
            C[A[l + 1]] --;
            if (A[l] > A[l + 1])
                break;
            if (A[l] == A[l + 1])
            {
                l --;
                continue;
            }
            while (!C[nxt[A[l]]])
                nxt[A[l]] = nxt[nxt[A[l]]];
            if (nxt[A[l]] < A[l + 1])
                break;
            if (nxt[A[l]] == A[l + 1] && used)
                break;
            used = 1;
            l --;
        }
        i = l;
        cnt ++;
    }
    return !printf("%d", cnt);
}

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

money.cpp: In function 'int main()':
money.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
money.cpp:9:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]), C[A[i]] ++;
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...