Submission #154539

#TimeUsernameProblemLanguageResultExecution timeMemory
154539arnold518MP3 Player (CEOI10_mp3player)C++14
0 / 100
1071 ms2140 KiB
#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=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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...