Submission #147916

#TimeUsernameProblemLanguageResultExecution timeMemory
147916nekiWiring (IOI17_wiring)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "wiring.h" #define maxn 100100 #define loop(i, a, b) for(int i=a;i<b;i++) typedef long long ll using namespace std; bool cmp(ll a, ll b) { return (abs(a)<abs(b))? 1:0;} ll min(ll a, ll b) { return (a<b)? a:b;} long long min_total_length (vector <int> red, vector <int> blue) { pair<ll, ll> com[maxn*2];n=red.size()+blue.size(); loop(i, 0, red.size()) com[i]({red[i], 1}); loop(i, 0, blue.size()) com[i+red.size()]({blue[i], -1}); sort(com, com+n, cmp);sort(red.begin(), red.end());sort(blue.begin(), blue.end()); ll dp[maxn*2], nek[maxn*2], ind[maxn*2], bal=maxn;loop(i, 0, 2*maxn) nek[i]=LLONG_MAX, dif=0; loop(i, 0, n){ ll ma=LLONG_MAX; bal+=com[i].second;dif+=com[i].first * com[i].second; if(com[i].second==1){ auto cl=lower_bound(blue.begin(), blue.end(), com[i].first); if(cl!=blue.end()) ma=min(ma, (*cl)-com[i].first); if(cl!=blue.begin()) ma=min(ma, com[i].first-(*prev(cl))); } else{ auto cl=lower_bound(red.begin(), red.end(), com[i].first); if(cl!=red.end()) ma=min(ma, (*cl)-com[i].first); if(cl!=red.begin()) ma=min(ma, com[i].first-(*prev(cl))); } dp[i]=min(dp[i-1]+ma, abs(dif-nek[bal])+dp[ind[bal]]); nek[bal]=dif;ind[bal]=i; } return dp[n-1]; }

Compilation message (stderr)

wiring.cpp:7:1: error: expected initializer before 'using'
 using namespace std;
 ^~~~~
wiring.cpp:9:10: error: 'll' was not declared in this scope
 bool cmp(ll a, ll b) { return (abs(a)<abs(b))? 1:0;}
          ^~
wiring.cpp:9:16: error: 'll' was not declared in this scope
 bool cmp(ll a, ll b) { return (abs(a)<abs(b))? 1:0;}
                ^~
wiring.cpp:9:20: error: expression list treated as compound expression in initializer [-fpermissive]
 bool cmp(ll a, ll b) { return (abs(a)<abs(b))? 1:0;}
                    ^
wiring.cpp:10:1: error: 'll' does not name a type
 ll min(ll a, ll b) { return (a<b)? a:b;}
 ^~
wiring.cpp:12:29: error: 'long long int min_total_length' redeclared as different kind of symbol
 long long min_total_length (vector <int> red, vector <int> blue) {
                             ^~~~~~
In file included from wiring.cpp:2:0:
wiring.h:3:11: note: previous declaration 'long long int min_total_length(std::vector<int>, std::vector<int>)'
 long long min_total_length(std::vector<int> r, std::vector<int> b);
           ^~~~~~~~~~~~~~~~
wiring.cpp:12:29: error: 'vector' was not declared in this scope
 long long min_total_length (vector <int> red, vector <int> blue) {
                             ^~~~~~
wiring.cpp:12:29: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from wiring.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
wiring.cpp:12:37: error: expected primary-expression before 'int'
 long long min_total_length (vector <int> red, vector <int> blue) {
                                     ^~~
wiring.cpp:12:47: error: 'vector' was not declared in this scope
 long long min_total_length (vector <int> red, vector <int> blue) {
                                               ^~~~~~
wiring.cpp:12:47: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from wiring.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
wiring.cpp:12:55: error: expected primary-expression before 'int'
 long long min_total_length (vector <int> red, vector <int> blue) {
                                                       ^~~