Submission #275843

# Submission time Handle Problem Language Result Execution time Memory
275843 2020-08-20T07:58:22 Z 임성재(#5103) Circus (Balkan15_CIRCUS) C++17
Compilation error
0 ms 0 KB
#include "circus.h"
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> piii;
const int inf = 1e9;
const ll INF = 1e18;

int n, m;
int dp[100010];
bool chk[100010];
set<int> s;
vector<int> p;
priority_queue<piii, vector<piii>, greater<piii>> pQ;

int put(int i) {
    

void init(int N, int M, int P[]){
    n = N;
    m = M;

    for(int i=0; i<n; i++) p.eb(P[i]);
    for(int i=0; i<p.size(); i++) s.insert(p[i]);

    pQ.em(0, mp(m, m));

    while(pQ.size()) {
        auto x = pQ.top();
        pQ.pop();

        if(chk[x.se.fi]) continue;
        chk[x.se.fi] = true;
        dp[x.se.fi] = x.fi;
        s.erase(x.se.fi);

        int i = x.se.fi;
        int c1 = -1, c2 = -1;

        if(s.lower_bound(i + dp[i]) != s.end()) c2 = *s.lower_bound(i + dp[i]);
        if(s.upper_bound(i - dp[i]) != s.begin()) c1 = *prev(s.upper_bound(i - dp[i]));

        if(c1 != -1) pQ.em(i - c1, mp(c1, i));
        if(c2 != -1) pQ.em(c2 - i, mp(c2, i));

        i = x.se.se;
        c1 = -1, c2 = -1;

        if(s.lower_bound(i + dp[i]) != s.end()) c2 = *s.lower_bound(i + dp[i]);
        if(s.upper_bound(i - dp[i]) != s.begin()) c1 = *prev(s.upper_bound(i - dp[i]));

        if(c1 != -1) pQ.em(i - c1, mp(c1, i));
        if(c2 != -1) pQ.em(c2 - i, mp(c2, i));
    }
}

int minLength(int D) {
    int ret = m - D;
    for(int i=0; i<p.size(); i++) {
        if(abs(p[i] - D) < dp[p[i]]) continue;
        ret = min(ret, abs(p[i] - D));
    }

    return ret;
}

Compilation message

circus.cpp: In function 'int put(int)':
circus.cpp:30:33: error: a function-definition is not allowed here before '{' token
   30 | void init(int N, int M, int P[]){
      |                                 ^
circus.cpp:68:22: error: a function-definition is not allowed here before '{' token
   68 | int minLength(int D) {
      |                      ^
circus.cpp:76:1: error: expected '}' at end of input
   76 | }
      | ^
circus.cpp:27:16: note: to match this '{'
   27 | int put(int i) {
      |                ^
circus.cpp:76:1: warning: no return statement in function returning non-void [-Wreturn-type]
   76 | }
      | ^
grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
   14 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf("%d", &P[i]);
      |   ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", &d);
      |   ~~~~~^~~~~~~~~~