Submission #154538

# Submission time Handle Problem Language Result Execution time Memory
154538 2019-09-22T15:43:50 Z arnold518 MP3 Player (CEOI10_mp3player) C++14
0 / 100
1000 ms 3324 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, Vmax, V2, ans;
pii A[MAXN+10];

bool decide(int X)
{
    int i, j;

    vector<int> S;
    for(i=1; i<=N; i++) if(A[i].second-A[i-1].second<=X) S.push_back(A[i].first);

    for(i=0; i<=Vmax; i++)
    {
        int now=i;
        for(j=0; j<S.size(); j++)
        {
            now+=S[j];
            if(now>Vmax) now=Vmax;
            if(now<0) now=0;
        }
        if(now==V2) { ans=i; return true; }
    }
    return false;
}

int main()
{
    int i, j;

    scanf("%d%d%d", &N, &Vmax, &V2);
    for(i=1; i<=N; i++)
    {
        char a; int b;
        scanf("\n%c%d", &a, &b);
        if(a=='+') A[i]=pii(1, b);
        else A[i]=pii(-1, b);
    }

    ll lo=0, hi=2e9+10;
    while(lo+1<hi)
    {
        ll mid=lo+hi>>1;
        if(decide(mid)) lo=mid;
        else hi=mid;
    }
    if(lo>2e9+5) printf("infinity");
    else
    {
        printf("%lld ", lo); decide(lo);
        printf("%d", ans);
    }
}

Compilation message

mp3player.cpp: In function 'bool decide(int)':
mp3player.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0; j<S.size(); j++)
                  ~^~~~~~~~~
mp3player.cpp: In function 'int main()':
mp3player.cpp:50:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         ll mid=lo+hi>>1;
                ~~^~~
mp3player.cpp:36:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
mp3player.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &Vmax, &V2);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
mp3player.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n%c%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 1716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 3324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 3276 KB Time limit exceeded
2 Halted 0 ms 0 KB -