Submission #259630

# Submission time Handle Problem Language Result Execution time Memory
259630 2020-08-08T05:39:26 Z dantoh000 Santa Claus (RMI19_santa) C++14
30 / 100
1000 ms 760 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int x[6000], h[6000], v[6000];
bool test(int l, int r){
    if (l > r) return false;
    multiset<int> ms;
    for (int i = 0; i < l; i++){
        if (h[i]){
            auto it = ms.lower_bound(v[i]);
            if (it != ms.end()) ms.erase(it);
        }
        else{
            ms.insert(v[i]);
        }
    }
    for (int i = l; i <= r; i++){
        if (h[i] == 0) ms.insert(v[i]);
    }
    for (int i = l; i <= r; i++){
        if (h[i] == 1){
            auto it = ms.lower_bound(v[i]);
            if (it != ms.end()) ms.erase(it);
        }
    }
    return ms.empty();
}
int main(){
    int tc;
    scanf("%d",&tc);
    while (tc--){
        scanf("%d",&n);
        if (n >= 6000) return 0;
        int lastelf = 0;
        for (int i = 0; i < n; i++){
            scanf("%d",&x[i]);
        }
        for (int i = 0; i < n; i++){
            scanf("%d",&h[i]);
            if (h[i] == 0) lastelf = i;
        }
        for (int i = 0; i < n; i++){
            scanf("%d",&v[i]);
        }
        int last = 0;
        for (int i = 0; i < n; i++){
            if (i < lastelf){
                printf("-1 ");
                continue;
            }
            while (test(last+1,i)){
                //printf("last %d can\n",last+1);
                last++;
            }
            if (test(last,i)){
                printf("%d ",2*x[i]-x[last]);
            }
            else printf("-1 ");
        }
        printf("\n");
    }

}

Compilation message

santa.cpp: In function 'int main()':
santa.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&tc);
     ~~~~~^~~~~~~~~~
santa.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&n);
         ~~~~~^~~~~~~~~
santa.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x[i]);
             ~~~~~^~~~~~~~~~~~
santa.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&h[i]);
             ~~~~~^~~~~~~~~~~~
santa.cpp:43:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&v[i]);
             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 384 KB Output is correct
3 Correct 915 ms 760 KB Output is correct
4 Execution timed out 1087 ms 760 KB Time limit exceeded
5 Execution timed out 1092 ms 640 KB Time limit exceeded
6 Incorrect 1 ms 256 KB Output isn't correct
7 Incorrect 0 ms 256 KB Output isn't correct
8 Incorrect 0 ms 256 KB Output isn't correct
9 Incorrect 0 ms 256 KB Output isn't correct
10 Incorrect 1 ms 256 KB Output isn't correct