Submission #477351

#TimeUsernameProblemLanguageResultExecution timeMemory
477351Ooops_sorryColouring a rectangle (eJOI19_colouring)C++14
0 / 100
195 ms102404 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ld long double #define ll long long #define int long long mt19937 rnd(51); int n, m; bool connect(int i, int j, int ii, int jj){ if (j > jj){ return 0; } int x = ((ii - i) + (jj - j)) / 2; int y = (jj - j) - x; if (i + x == ii + y && j + x == jj - y && i + x < n && j + x < m){ return 1; } else{ return 0; } } int take_ans(vector<pair<pair<int,int>, int>> a, vector<pair<pair<int,int>, int>> b){ vector<pair<int,int>> need(b.size()); vector<vector<vector<int>>> dp(b.size() + 1, vector<vector<int>>(a.size() + 1, vector<int>(a.size() + 1, 1e18))); for (int j = 0; j < b.size(); j++){ vector<int> ind; for (int i = 0; i < a.size(); i++){ if (connect(a[i].first.first, a[i].first.second, b[j].first.first, b[j].first.second)){ ind.pb(i); } } if (ind.size() > 0){ need[j] = {ind[0], ind.back()}; } } dp[0][a.size()][a.size()] = 0; for (int i = 1; i <= b.size(); i++){ for (int j = 0; j <= a.size(); j++){ for (int k = 0; k <= a.size(); k++){ dp[i][j][k] = min(dp[i][j][k], b[i - 1].second + dp[i - 1][j][k]); int add = dp[i - 1][j][k]; if (j == a.size() && k == a.size()){ for (int f = need[i - 1].first; f <= need[i - 1].second; f++) add += a[f].second; dp[i][need[i - 1].first][need[i - 1].second] = min(dp[i][need[i - 1].first][need[i - 1].second], add); } else{ if (need[i - 1].second < j || need[i - 1].first > k){ for (int f = need[i - 1].first; f <= need[i - 1].second; f++) add += a[f].second; dp[i][need[i - 1].first][need[i - 1].second] = min(dp[i][need[i - 1].first][need[i - 1].second], add); } else{ for (int f = k + 1; f <= need[i - 1].second; f++) add += a[f].second; for (int f = need[i - 1].first; f < j; f++) add += a[f].second; dp[i][need[i - 1].first][need[i - 1].second] = min(dp[i][need[i - 1].first][need[i - 1].second], add); } } } } } int ans = 1e18; for (int i = 0; i <= a.size(); i++) for (int j = 0; j <= a.size(); j++) ans = min(ans, dp[b.size()][i][j]); return ans; } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; vector<pair<pair<int,int>, int>> l0, l1, r0, r1; int f = 0, s = m - 1; for (int i = 0; i < n + m - 1; i++){ int a; cin >> a; if ((f + s) & 1){ l1.pb({{f, s}, a}); } else{ l0.pb({{f, s}, a}); } if (s > 0) s--; else f++; } f = 0, s = 0; for (int i = 0; i < n + m - 1; i++){ int a; cin >> a; if ((f + s) & 1){ r1.pb({{f, s}, a}); } else{ r0.pb({{f, s}, a}); } if (s + 1 < m) s++; else f++; } cout << take_ans(l0, r0) + take_ans(l1, r1) << endl; return 0; }

Compilation message (stderr)

colouring.cpp: In function 'long long int take_ans(std::vector<std::pair<std::pair<long long int, long long int>, long long int> >, std::vector<std::pair<std::pair<long long int, long long int>, long long int> >)':
colouring.cpp:31:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int j = 0; j < b.size(); j++){
      |                     ~~^~~~~~~~~~
colouring.cpp:33:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (int i = 0; i < a.size(); i++){
      |                         ~~^~~~~~~~~~
colouring.cpp:43:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 1; i <= b.size(); i++){
      |                     ~~^~~~~~~~~~~
colouring.cpp:44:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int j = 0; j <= a.size(); j++){
      |                         ~~^~~~~~~~~~~
colouring.cpp:45:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             for (int k = 0; k <= a.size(); k++){
      |                             ~~^~~~~~~~~~~
colouring.cpp:48:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if (j == a.size() && k == a.size()){
      |                     ~~^~~~~~~~~~~
colouring.cpp:48:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if (j == a.size() && k == a.size()){
      |                                      ~~^~~~~~~~~~~
colouring.cpp:67:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i <= a.size(); i++) for (int j = 0; j <= a.size(); j++) ans = min(ans, dp[b.size()][i][j]);
      |                     ~~^~~~~~~~~~~
colouring.cpp:67:59: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i <= a.size(); i++) for (int j = 0; j <= a.size(); j++) ans = min(ans, dp[b.size()][i][j]);
      |                                                         ~~^~~~~~~~~~~
#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...