Submission #477342

#TimeUsernameProblemLanguageResultExecution timeMemory
477342Ooops_sorryColouring a rectangle (eJOI19_colouring)C++14
30 / 100
165 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){ set<pair<int,int>> st; while(i < n && j < m){ st.insert({i, j}); i++, j++; } while(ii < n && jj >= 0){ if (st.find({ii, jj}) != st.end()) return 1; ii++, jj--; } 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:30: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]
   30 |     for (int j = 0; j < b.size(); j++){
      |                     ~~^~~~~~~~~~
colouring.cpp:32: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]
   32 |         for (int i = 0; i < a.size(); i++){
      |                         ~~^~~~~~~~~~
colouring.cpp:42: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]
   42 |     for (int i = 1; i <= b.size(); i++){
      |                     ~~^~~~~~~~~~~
colouring.cpp:43: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]
   43 |         for (int j = 0; j <= a.size(); j++){
      |                         ~~^~~~~~~~~~~
colouring.cpp:44: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]
   44 |             for (int k = 0; k <= a.size(); k++){
      |                             ~~^~~~~~~~~~~
colouring.cpp:47: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]
   47 |                 if (j == a.size() && k == a.size()){
      |                     ~~^~~~~~~~~~~
colouring.cpp:47: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]
   47 |                 if (j == a.size() && k == a.size()){
      |                                      ~~^~~~~~~~~~~
colouring.cpp:66: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]
   66 |     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:66: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]
   66 |     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...