답안 #154542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154542 2019-09-22T15:50:56 Z arnold518 MP3 Player (CEOI10_mp3player) C++14
20 / 100
1000 ms 3316 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=2; i<=N; i++) if(A[i].second-A[i-1].second<=X) S.push_back(A[i].first);

    for(i=Vmax; i>=0; 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);
         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 404 KB Output is correct
2 Correct 28 ms 352 KB Output is correct
3 Correct 27 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 305 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1188 KB Output is correct
2 Correct 17 ms 1184 KB Output is correct
3 Correct 22 ms 1488 KB Output is correct
4 Incorrect 17 ms 1144 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1696 KB Output is correct
2 Correct 27 ms 1796 KB Output is correct
3 Incorrect 25 ms 1616 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1067 ms 3316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 2932 KB Time limit exceeded
2 Halted 0 ms 0 KB -