Submission #370781

#TimeUsernameProblemLanguageResultExecution timeMemory
370781cpp219Strange Device (APIO19_strange_device)C++14
65 / 100
531 ms31932 KiB
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 1e6 + 3; const ll inf = 1e9 + 7; LL a[N]; ll n,A,B,q,total; vector<LL> v; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>A>>B; q = A/__gcd(B + 1,A); total = q * B; for (ll i = 1;i <= n;i++){ cin>>a[i].fs>>a[i].sc; a[i].fs %= total; a[i].sc %= total; if (a[i].fs <= a[i].sc) v.push_back(a[i]); else{ v.push_back({0,a[i].sc}); v.push_back({a[i].fs,total - 1}); } } sort(v.begin(),v.end()); ll mx = -inf,ans = 0; for (auto i : v){ if (i.sc <= mx) continue; if (i.fs > mx) ans += i.sc - i.fs + 1; else ans += max(0ll,i.sc - mx); mx = max(mx,i.sc); } cout<<ans; }

Compilation message (stderr)

strange_device.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
strange_device.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      | 
strange_device.cpp: In function 'int main()':
strange_device.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...