Submission #200512

#TimeUsernameProblemLanguageResultExecution timeMemory
200512HellAngelWiring (IOI17_wiring)C++14
100 / 100
93 ms15048 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; /// dont use define int long long void Minimize(ll &a, const ll &b) { a = min(a, b); } ll min_total_length(vector<int> r, vector<int> b) { vector<vector<ll>> dp(0), prf(0); vector<pair<ll, ll>> vt; for(auto i: r) vt.emplace_back(i, 0); for(auto i: b) vt.emplace_back(i, 1); sort(vt.begin(), vt.end()); int cur = 0; while(cur < vt.size()) { int nxt = cur; vector<ll> nprf = {0}; for(; nxt < vt.size() && vt[nxt].second == vt[cur].second; nxt++) { nprf.push_back(vt[nxt].first + nprf.back()); } cur = nxt; vector<ll> blank(nprf.size(), (ll)1e17); dp.push_back(blank); prf.push_back(nprf); } auto Get = [&](ll x, ll y) { ll ans = prf[x][y] - prf[x][y - 1]; return ans; }; dp[0][0] = 0; for(int i = 0; i < dp.size(); i++) { for(int j = 0; j + 1 < dp[i].size(); j++) { if(i > 0) Minimize(dp[i][j + 1], dp[i][j] + Get(i, j + 1) - Get(i - 1, prf[i - 1].size() - 1)); if(i + 1 < dp.size()) { if(prf[i].size() - j - 1 <= prf[i + 1].size() - 1) { Minimize(dp[i + 1][prf[i].size() - j - 1], dp[i][j] + prf[i + 1][prf[i].size() - j - 1] - prf[i][prf[i].size() - 1] + prf[i][j]); } Minimize(dp[i][j + 1], dp[i][j] - Get(i, j + 1) + Get(i + 1, 1)); } } if(i + 1 < dp.size()) Minimize(dp[i + 1][0], dp[i].back()); else return dp[i].back(); } return 0; }

Compilation message (stderr)

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(cur < vt.size())
           ~~~~^~~~~~~~~~~
wiring.cpp:22:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; nxt < vt.size() && vt[nxt].second == vt[cur].second; nxt++)
               ~~~~^~~~~~~~~~~
wiring.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < dp.size(); i++)
                    ~~^~~~~~~~~~~
wiring.cpp:39:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j + 1 < dp[i].size(); j++)
                        ~~~~~~^~~~~~~~~~~~~~
wiring.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(i + 1 < dp.size()) 
                ~~~~~~^~~~~~~~~~~
wiring.cpp:51:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i + 1 < dp.size()) Minimize(dp[i + 1][0], dp[i].back());
            ~~~~~~^~~~~~~~~~~
#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...