Submission #275745

# Submission time Handle Problem Language Result Execution time Memory
275745 2020-08-20T07:28:35 Z 임성재(#5103) Circus (Balkan15_CIRCUS) C++17
0 / 100
249 ms 5872 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 close(int x, int md) {
    int ret = inf, y = -1;
    int k = lower_bound(all(p), p[x] + md) - p.begin();
    
    auto it = s.lower_bound(k);
    if(it != s.end()) {
        if(p[*it] - p[x] < ret) {
            ret = p[*it] - p[x];
            y = *it;
        }
    }

    k = upper_bound(all(p), p[x] - md) - p.begin() - 1;
    
    it = s.upper_bound(k);
    if(it != s.begin()) {
        if(p[x] - p[*prev(it)] < ret) {
            ret =p[x] - p[*prev(it)];
            y = *prev(it);
        }
    }

    return y;
}

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

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

    p.eb(0);
    p.eb(m);
    sort(all(p));

    for(int i=0; i<p.size(); i++) s.insert(i);

    pQ.em(0, mp(p.size()-1, p.size()-1));

    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);

        if(close(x.se.fi, dp[x.se.fi]) >= 0)
            pQ.em(abs(p[close(x.se.fi, dp[x.se.fi])] - p[x.se.fi]), mp(close(x.se.fi, dp[x.se.fi]), x.se.fi));
        if(close(x.se.se, dp[x.se.se]) >= 0)
            pQ.em(abs(p[close(x.se.se, dp[x.se.se])] - p[x.se.se]), mp(close(x.se.se, dp[x.se.se]), x.se.se));
    }

    /*for(int i = 0; i < p.size(); i++) 
        cout << dp[i] << " ";*/
}

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

    return ret;
}

Compilation message

circus.cpp: In function 'void init(int, int, int*)':
circus.cpp:62:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=0; i<p.size(); i++) s.insert(i);
      |                  ~^~~~~~~~~
circus.cpp: In function 'int minLength(int)':
circus.cpp:87:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i=0; i<p.size(); i++) {
      |                  ~^~~~~~~~~
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);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 249 ms 5872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 249 ms 5872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 249 ms 5872 KB Output isn't correct
2 Halted 0 ms 0 KB -