Submission #276455

# Submission time Handle Problem Language Result Execution time Memory
276455 2020-08-20T12:57:17 Z sjimed Circus (Balkan15_CIRCUS) C++14
40 / 100
4000 ms 17988 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];
vector<int> p;
priority_queue<piii, vector<piii>, greater<piii>> pQ;

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));
    p.erase(unique(all(p)), p.end());

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

    while(pQ.size()) {
        int cost = pQ.top().fi;
        int x = pQ.top().se.fi;
        int par = pQ.top().se.se;
        pQ.pop();

        if(x >= par && x+1 < p.size()) pQ.em(p[x+1] - p[par], mp(x+1, par));
        else if(x <= par && x-1 >= 0) pQ.em(p[par] - p[x-1], mp(x-1, par));

        if(chk[x]) continue;
        chk[x] = true;
        dp[x] = cost;        

        int k = lower_bound(all(p), p[x] + cost) - p.begin();
        if(k < p.size()) pQ.em(p[k] - p[x], mp(k, x));

        k = upper_bound(all(p), p[x] - cost) - p.begin() - 1;
        if(k >= 0) pQ.em(p[x] - p[k], mp(k, x));
    }
}

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:46:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(x >= par && x+1 < p.size()) pQ.em(p[x+1] - p[par], mp(x+1, par));
      |                        ~~~~^~~~~~~~~~
circus.cpp:54:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if(k < p.size()) pQ.em(p[k] - p[x], mp(k, x));
      |            ~~^~~~~~~~~~
circus.cpp: In function 'int minLength(int)':
circus.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     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 Execution timed out 4045 ms 5600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 553 ms 512 KB Output is correct
6 Correct 537 ms 520 KB Output is correct
7 Correct 578 ms 532 KB Output is correct
8 Correct 535 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 553 ms 512 KB Output is correct
6 Correct 537 ms 520 KB Output is correct
7 Correct 578 ms 532 KB Output is correct
8 Correct 535 ms 540 KB Output is correct
9 Incorrect 3630 ms 17988 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4045 ms 5600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4045 ms 5600 KB Time limit exceeded
2 Halted 0 ms 0 KB -