답안 #259617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259617 2020-08-08T04:33:12 Z dantoh000 Santa Claus (RMI19_santa) C++14
20 / 100
1000 ms 816 KB
#include <bits/stdc++.h>
using namespace std;
int n;
int x[6000], h[6000], v[6000];
bool test(int l, int r){
    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);
        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]);
        }
        for (int i = 0; i < n; i++){
            int lo = 0, hi = i;
            while (lo < hi){
                int mid = (lo+hi+1)/2;
                if (test(mid,i)){
                    lo = mid;
                }
                else hi = mid-1;
            }
            if (test(lo,i) && i >= lastelf){
                printf("%d ",2*x[i]-x[lo]);
            }
            else printf("-1 ");
        }
        printf("\n");
    }

}

Compilation message

santa.cpp: In function 'int main()':
santa.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&tc);
     ~~~~~^~~~~~~~~~
santa.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&n);
         ~~~~~^~~~~~~~~
santa.cpp:34:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x[i]);
             ~~~~~^~~~~~~~~~~~
santa.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&h[i]);
             ~~~~~^~~~~~~~~~~~
santa.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&v[i]);
             ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 25 ms 384 KB Output is correct
3 Execution timed out 1090 ms 632 KB Time limit exceeded
4 Execution timed out 1089 ms 632 KB Time limit exceeded
5 Execution timed out 1091 ms 764 KB Time limit exceeded
6 Execution timed out 1073 ms 760 KB Time limit exceeded
7 Execution timed out 254 ms 816 KB Time limit exceeded (wall clock)
8 Execution timed out 249 ms 760 KB Time limit exceeded (wall clock)
9 Execution timed out 247 ms 760 KB Time limit exceeded (wall clock)
10 Execution timed out 277 ms 804 KB Time limit exceeded (wall clock)