답안 #856172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856172 2023-10-02T18:41:17 Z Benmath popa (BOI18_popa) C++14
0 / 100
80 ms 436 KB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include<popa.h>
#include <bits/stdc++.h>

using namespace std;
using pii = pair<int,pair<int,int>>;
int solver(int prvi, int drugi, int lijevo[], int desno[]){
    for(int i = prvi; i <= drugi; i++){
        if(lijevo[i] <= prvi and drugi <= desno[i]){
            return i;
        }
    }
}
int solve(int N, int* Left, int* Right){
    int n = N;
    int lijevo[n];
    int desno[n];
    for(int i = 0; i < n; i++){
        Left[i] = -1;
        Right[i] = -1;
       lijevo[i] = i;
       int l = 0;
       int r = i - 1;
       while(l <= r){
           int mid = (l + r)/2;
           if(query(mid, i, i, i) == 1){
               lijevo[i] = min(lijevo[i] , mid);
               r = mid - 1;
           }else{
               l = mid + 1;
           }
       }
       l = i + 1;
       desno[i] = i;
       r = n - 1;
       while(l <= r){
           int mid = (l + r)/2;
           if(query(i,mid, i, i) == 1){
               desno[i] = max(desno[i], mid);
               l = mid + 1;
           }else{
               r = mid - 1;
           }
       }
    }
    int root = solver(0,n - 1, lijevo, desno);
    int interval1 = 0;
    queue<pair<int,pair<int,int>>>q;
    q.push({root,{0, n - 1}});
    while(!q.empty()){
        pii a = q.front();
        q.pop();
        int trenutni = a.first;
        int prvi = a.second.first;
        int drugi = a.second.second;
        if(prvi < trenutni){
            int x = solver(prvi, trenutni - 1, lijevo, desno);
            Left[trenutni] = x;
            q.push({x,{prvi,trenutni - 1}});
        }
        if(trenutni < drugi){
            int x = solver(drugi, trenutni - 1, lijevo,desno);
            Right[trenutni] = x;
            q.push({x,{trenutni + 1, drugi}});
        }
    }
    return root;
    
}

Compilation message

popa.cpp: In function 'int solve(int, int*, int*)':
popa.cpp:53:9: warning: unused variable 'interval1' [-Wunused-variable]
   53 |     int interval1 = 0;
      |         ^~~~~~~~~
popa.cpp: In function 'int solver(int, int, int*, int*)':
popa.cpp:19:1: warning: control reaches end of non-void function [-Wreturn-type]
   19 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 436 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 80 ms 428 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 344 KB too many queries
2 Halted 0 ms 0 KB -