Submission #1023743

#TimeUsernameProblemLanguageResultExecution timeMemory
1023743vjudge1JJOOII 2 (JOI20_ho_t2)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #include <vector> using namespace std; #define int long long #define ff first #define ss second #define tobit(n) bitset<20>(n) //выводит 20 элементов в битовую систему #define all(v) (v).begin(), (v).end() #define rtt(v, k) rotate(v.begin(), v.begin() + k, v.end()); //move k elements back const int MOD = 1e9 + 7; int binpownm(int n, int m){ if(m == 1) return n; if(m % 2 == 0){ int t = binpownm(n, m / 2); return t * t; } else return binpownm(n, m - 1) * n; } bool sortt(pair<int, double> a, pair<int, double> b){ return a.ss < b.ss; } struct sturc_t { int ff_, ss_, tt_; }; int knaps(vector<int>& cur, vector<int>& cst, int S){ vector<vector<int>> dp(S + 1, vector<int> (cur.size() + 1, 0)); for(int j = 1; j <= cur.size(); j++){ for(int w = 1; w <= S; w++){ if(cur[j-1] <= w){ dp[w][j] = max(dp[w][j - 1], dp[w - cur[j - 1]][j - 1] + cst[j - 1]); } else dp[w][j] = dp[w][j - 1]; } } return dp[S][cur.size()]; } int knapsack2(vector<sturc_t>& v, int S){ vector<int> dp(S + 1, 0); for(auto& to : v){ for(int q = 0; q < to.tt_; q++){ for(int w = S; w >= to.ss_; w--){ dp[w] = max(dp[w], dp[w - to.ss_] + to.ff_); } } } return dp[S]; } signed main(){ int n, k, res = -1, cst = 0; cin >> n >> k; string s; cin >> s; vector<int> a(n), b(n), c(n); a[0] = (s[0] == 'O') - 1; c[0] = (s[0] == 'O'); for(int i = 1; i < n; i++){ a[i] = (s[i] == 'O') ? i : a[i - 1]; c[i] = c[i - 1] + (s[i] == 'O'); } b[n - 1] = (s[n - 1] == 'O') ? n - 1 : -1; for(int i = n - 2; i >= 0; i--){ b[i] = (s[i] == 'O') ? i : b[i + 1]; } vector<int> res1(n, -1); deque<int> d; for(auto to : a) cout << to << " "; cout << "\n"; for(auto to : b) cout << to << " "; cout << "\n"; for(auto to : c) cout << to << " "; cout << "\n\n\n"; for(int i = 0; i < n; i++){ if(s[i] != 'J') continue; if(!d.empty()) cst += i - d.back() - 1; d.push_back(i); if((int)d.size() == k+1){ int f = d.front(); d.pop_front(); cst -= d.front() - f - 1; } if ((int)d.size() == k) res1[i] = cst; } vector<int> res2(n, -1); d.clear(); cst = 0; for(int i = n - 1; i >= 0; i--){ if(s[i] != 'I') continue; if(!d.empty()) cst += d.back() - i - 1; d.push_back(i); if((int)d.size() == k + 1){ int f = d.front(); d.pop_front(); cst -= f - d.front() - 1; } if((int)d.size() == k) res2[i] = cst; } for(auto to : res1) cout << to << " "; cout << "\n"; for(auto to : res2) cout << to << " "; cout << "\n"; for(int i = 0; i < n; i++){ if(res1[i] == -1) continue; for (int j = i + 2; j < n; j++){ if(res2[j] == -1 || c[j - 1] - c[i] < k) continue; int cst = res1[i] + res2[j] + (j - i - 1 - k); if(res == -1 || res > cst) res = cst; } } cout << res; } // NEED TO FAST CIN && COUT // const int fastIO = [](){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();

Compilation message (stderr)

ho_t2.cpp: In function 'long long int knaps(std::vector<long long int>&, std::vector<long long int>&, long long int)':
ho_t2.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int j = 1; j <= cur.size(); j++){
      |                    ~~^~~~~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:57:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   57 |     for(auto to : a) cout << to << " "; cout << "\n";
      |     ^~~
ho_t2.cpp:57:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   57 |     for(auto to : a) cout << to << " "; cout << "\n";
      |                                         ^~~~
ho_t2.cpp:58:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   58 |     for(auto to : b) cout << to << " "; cout << "\n";
      |     ^~~
ho_t2.cpp:58:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   58 |     for(auto to : b) cout << to << " "; cout << "\n";
      |                                         ^~~~
ho_t2.cpp:59:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   59 |     for(auto to : c) cout << to << " "; cout << "\n\n\n";
      |     ^~~
ho_t2.cpp:59:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   59 |     for(auto to : c) cout << to << " "; cout << "\n\n\n";
      |                                         ^~~~
ho_t2.cpp:81:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   81 |     for(auto to : res2) cout << to << " "; cout << "\n";
      |     ^~~
ho_t2.cpp:81:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   81 |     for(auto to : res2) cout << to << " "; cout << "\n";
      |                                            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...