Submission #749595

# Submission time Handle Problem Language Result Execution time Memory
749595 2023-05-28T09:44:16 Z 반딧불(#9967) Fruits (NOI22_fruits) C++17
0 / 100
107 ms 11348 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int arr[400002];
bool taken[400002];
ll cost[400002];

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d", &arr[i]);
        if(arr[i] != -1) taken[arr[i]] = 1;
    }
    for(int i=1; i<=n; i++) scanf("%lld", &cost[i]);

    vector<int> v; /// ���� �� �� ū �� ����
    vector<int> used;
    for(int i=n; i>=1; i--) if(!taken[i]) v.push_back(i);
    queue<int> overfits;
    int ans = 0, small = 0, overfit = 0, biggest = 0, ignored = 0;

    for(int i=1; i<=n; i++){
        if(arr[i] == -1){
            bool erased = 0;
            while(!v.empty() && v.back() < biggest) erased = 1, v.pop_back(), small++;
            if(!v.empty()){
                if(erased || small) overfit++, overfits.push(v.back());
                biggest = v.back(), v.pop_back();
                ans++;
            }
        }
        else{
            while(!overfits.empty() && overfits.front() <= arr[i]) overfit--, overfits.pop();
            if(biggest < arr[i]){
                biggest = arr[i];
                ans++;
                ignored = 0;
            }
            else{
                ignored++;
                if(overfit <= small && overfit <= ignored){
                    ignored = 0;
                    biggest = arr[i];
                    overfit = 0;
                    vector<int> tmp;
                    while(!overfits.empty()) tmp.push_back(overfits.back()), overfits.pop();
                    while(!tmp.empty()) v.push_back(tmp.back()), tmp.pop_back();
                }
            }
        }
//        printf("%d: ans %d, overfit %d, small %d, biggest %d\n", i, ans, overfit, small, biggest);
        printf("%d ", ans);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:18:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     for(int i=1; i<=n; i++) scanf("%lld", &cost[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 11088 KB Output is correct
2 Incorrect 107 ms 11348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -