Submission #1060024

#TimeUsernameProblemLanguageResultExecution timeMemory
1060024dozer봉쇄 시간 (IOI23_closing)C++17
0 / 100
1082 ms9696 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; #define sp " " #define endl "\n" #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define LL node * 2 #define RR node * 2 + 1 #define ll long long const int modulo = 1e9 + 7; const ll INF = 2e18 + 7; int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) { vector<ll> lft, rgt; lft.pb(0), rgt.pb(0); ll sum = 0; for (int i = X - 1; i >= 0; i--){ sum += W[i]; lft.pb(lft.back() + sum); } sum = 0; for (int i = Y + 1; i < N; i++){ sum += W[i - 1]; rgt.pb(rgt.back() + sum); } int ans = 0; //todo : no one can reach the other { vector<ll> merge(2 * (N + 1), INF); for (int i = 0; i < lft.size(); i++){ for (int j = 0; j < rgt.size(); j++){ merge[i + j] = min(merge[i + j], lft[i] + rgt[j]); } } vector<ll> cost(N, 0); ll sum = 0; for (int i = X; i <= Y; i++){ if (i > X){ cost[i] = cost[i - 1] + W[i - 1]; sum += cost[i]; } ll curr_sum = sum, pref = 0; for (int j = Y; j >= X; j--){ if (j < Y){ pref += W[j]; curr_sum += max((ll)0, pref - cost[j]); } if (curr_sum > K) continue; int pos = upper_bound(merge.begin(), merge.end(), K - curr_sum) - merge.begin(); ans = max(ans, (Y - j + 1) + (i - X + 1) + (pos - 1)); } } } //todo : X can reach Y { vector<ll> merge(2 * (N + 1), INF); for (int i = 0; i < lft.size(); i++){ for (int j = 0; j < rgt.size(); j++){ merge[i + 2 * j] = min(merge[i + 2 * j], lft[i] + rgt[j]); } } vector<ll> cost(N, 0); ll sum = 0; for (int i = X; i <= Y; i++){ if (i > X){ cost[i] = cost[i - 1] + W[i - 1]; sum += cost[i]; } ll curr_sum = sum, pref = 0; for (int j = Y; j >= X; j--){ if (j < Y){ pref += W[j]; curr_sum += max((ll)0, pref - cost[j]); } if (curr_sum > K || i != Y) continue; int pos = upper_bound(merge.begin(), merge.end(), K - curr_sum) - merge.begin(); ans = max(ans, (Y - j + 1) + (i - X + 1) + (pos - 1)); } } } //todo : Y can reach X { vector<ll> merge(2 * (N + 1), INF); for (int i = 0; i < lft.size(); i++){ for (int j = 0; j < rgt.size(); j++){ merge[2 * i + j] = min(merge[2 * i + j], lft[i] + rgt[j]); } } vector<ll> cost(N, 0); ll sum = 0; for (int i = X; i <= Y; i++){ if (i > X){ cost[i] = cost[i - 1] + W[i - 1]; sum += cost[i]; } ll curr_sum = sum, pref = 0; for (int j = Y; j >= X; j--){ if (j < Y){ pref += W[j]; curr_sum += max((ll)0, pref - cost[j]); } if (curr_sum > K || j != X) continue; int pos = upper_bound(merge.begin(), merge.end(), K - curr_sum) - merge.begin(); ans = max(ans, (Y - j + 1) + (i - X + 1) + (pos - 1)); } } } //todo : both can reach each other { vector<ll> merge(2 * (N + 1), INF); for (int i = 0; i < lft.size(); i++){ for (int j = 0; j < rgt.size(); j++){ merge[2 * i + j * 2] = min(merge[2 * i + j * 2], lft[i] + rgt[j]); } } vector<ll> cost(N, 0); ll sum = 0; for (int i = X; i <= Y; i++){ if (i > X){ cost[i] = cost[i - 1] + W[i - 1]; sum += cost[i]; } ll curr_sum = sum, pref = 0; for (int j = Y; j >= X; j--){ if (j < Y){ pref += W[j]; curr_sum += max((ll)0, pref - cost[j]); } if (curr_sum > K || j != X || i != Y) continue; int pos = upper_bound(merge.begin(), merge.end(), K - curr_sum) - merge.begin(); ans = max(ans, (Y - j + 1) + (i - X + 1) + (pos - 1)); } } } return ans; } /* int main() { fileio(); int Q; assert(1 == scanf("%d", &Q)); std::vector<int> N(Q), X(Q), Y(Q); std::vector<long long> K(Q); std::vector<std::vector<int>> U(Q), V(Q), W(Q); for (int q = 0; q < Q; q++) { assert(4 == scanf("%d %d %d %lld", &N[q], &X[q], &Y[q], &K[q])); U[q].resize(N[q] - 1); V[q].resize(N[q] - 1); W[q].resize(N[q] - 1); for (int i = 0; i < N[q] - 1; ++i) { assert(3 == scanf("%d %d %d", &U[q][i], &V[q][i], &W[q][i])); } } fclose(stdin); std::vector<int> result(Q); for (int q = 0; q < Q; q++) { result[q] = max_score(N[q], X[q], Y[q], K[q], U[q], V[q], W[q]); } for (int q = 0; q < Q; q++) { printf("%d\n", result[q]); } fclose(stdout); return 0; }*/

Compilation message (stderr)

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i = 0; i < lft.size(); i++){
      |                         ~~^~~~~~~~~~~~
closing.cpp:43:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             for (int j = 0; j < rgt.size(); j++){
      |                             ~~^~~~~~~~~~~~
closing.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int i = 0; i < lft.size(); i++){
      |                         ~~^~~~~~~~~~~~
closing.cpp:77:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             for (int j = 0; j < rgt.size(); j++){
      |                             ~~^~~~~~~~~~~~
closing.cpp:111:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         for (int i = 0; i < lft.size(); i++){
      |                         ~~^~~~~~~~~~~~
closing.cpp:112:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |             for (int j = 0; j < rgt.size(); j++){
      |                             ~~^~~~~~~~~~~~
closing.cpp:146:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |         for (int i = 0; i < lft.size(); i++){
      |                         ~~^~~~~~~~~~~~
closing.cpp:147:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  147 |             for (int j = 0; j < rgt.size(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...