Submission #1155105

#TimeUsernameProblemLanguageResultExecution timeMemory
1155105andrewpTraffic (IOI10_traffic)C++20
0 / 100
17 ms31552 KiB
#include <bits/stdc++.h>  
#include "traffic.h"
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())     
const int N=1e6+10;  

ll n, ps[N], ss[N];
ll pss[N], sss[N]; 

int LocateCentre(int N_,int P[],int S[],int D[]) {
    n=N;
    for (int i=1; i<=n; i++) {
        ps[i]=ps[i-1]+P[i-1];
        pss[i]=pss[i-1]+ps[i];  
    }
    for (int i=n; i>=1; i--) { 
        ss[i]=ss[i+1]+P[i-1]; 
        sss[i]=sss[i+1]+ss[i];  
    }
    ll ans=(ll)(1e18), ret=0;
    for (int i=1; i<=n; i++) {
        if (ans>pss[i-1]+sss[i+1]) {
            ans=pss[i-1]+sss[i+1];
            ret=i;
        }
    }
    return (ret-1);
}

// int main () {    
//     ios::sync_with_stdio(false), cin.tie(0); 
            

//     return 0;
// }          

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:18:14: warning: iteration 1000009 invokes undefined behavior [-Waggressive-loop-optimizations]
   18 |         ps[i]=ps[i-1]+P[i-1];
      |         ~~~~~^~~~~~~~~~~~~~~
traffic.cpp:17:20: note: within this loop
   17 |     for (int i=1; i<=n; i++) {
      |                   ~^~~
traffic.cpp:27:33: warning: iteration 1000008 invokes undefined behavior [-Waggressive-loop-optimizations]
   27 |         if (ans>pss[i-1]+sss[i+1]) {
      |                          ~~~~~~~^
traffic.cpp:26:20: note: within this loop
   26 |     for (int i=1; i<=n; i++) {
      |                   ~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...