제출 #70192

#제출 시각아이디문제언어결과실행 시간메모리
70192funcsr코알라 (APIO17_koala)C++17
67 / 100
957 ms1264 KiB
#include "koala.h" #include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int N, W; tuple<int,int,int> dp[201]; int simulation(vector<int> cost, int l, int r) { rep(i, W+1) dp[i] = make_tuple(0, 0, 0); rep(i, N) { assert(cost[i] > 0); for (int j=W-cost[i]; j>=0; j--) { dp[j+cost[i]] = max(dp[j+cost[i]], make_tuple(get<0>(dp[j])+(i+1), get<1>(dp[j])+1, get<2>(dp[j])-(l<=i+1&&i+1<=r))); } } int lo = -get<2>(dp[W]); rep(i, W+1) dp[i] = make_tuple(0, 0, 0); rep(i, N) { assert(cost[i] > 0); for (int j=W-cost[i]; j>=0; j--) { dp[j+cost[i]] = max(dp[j+cost[i]], make_tuple(get<0>(dp[j])+(i+1), get<1>(dp[j])+1, get<2>(dp[j])+(l<=i+1&&i+1<=r))); } } int hi = get<2>(dp[W]); assert(lo==hi); return lo; } int perm[100]; void solve(int l, int r, vector<int> set) { assert(r-l+1 == set.size()); assert(l<=r); //cout<<"["<<l<<","<<r<<"] {";for(int x: set)cout<<x<<",";cout<<"}\n"; if (l == r) { perm[set[0]] = l; return; } pair<int, P> mp = make_pair(INF, P(-1, -1)); for (int outside=1; outside<=100; outside++) { for (int k=2; k<=100; k++) { if ((outside-1)*(N-(r-l+1)) + (k-1)*(r-l+1) > W) continue; vector<int> cost(N); for (int i=1; i<=N; i++) { if (l <= i && i <= r) cost[i-1] = k; else cost[i-1] = outside; } int left = simulation(cost, l, r); int right = (r-l+1)-left; if (left==0||right==0)continue; mp = min(mp, make_pair(abs(left-right), P(k, outside))); if (mp._1 == 0) break; } if (mp._1 == 0) break; } int val = mp._2._1; int outside = mp._2._2; //cout<<"val="<<val<<", outside="<<outside<<": "<<mp._1<<"\n"; assert(val!=-1); int B[100], R[100]; rep(i, N) B[i] = outside-1; for (int i : set) B[i] = val-1; playRound(B, R); vector<int> left, right; for (int i : set) { if (R[i] >= val) right.pb(i); else left.pb(i); } solve(l, l+left.size()-1, left); solve(l+left.size(), r, right); } int solve2(int l, int r, vector<int> set) { assert(r-l+1 == set.size()); assert(l<=r); //cout<<"["<<l<<","<<r<<"] {";for(int x: set)cout<<x<<",";cout<<"}\n"; if (l == r) return l; pair<int, P> mp = make_pair(INF, P(-1, -1)); for (int outside=1; outside<=100; outside++) { for (int k=2; k<=100; k++) { if ((outside-1)*(N-(r-l+1)) + (k-1)*(r-l+1) > W) continue; vector<int> cost(N); for (int i=1; i<=N; i++) { if (l <= i && i <= r) cost[i-1] = k; else cost[i-1] = outside; } int left = simulation(cost, l, r); int right = (r-l+1)-left; if (right==0)continue; mp = min(mp, make_pair(right, P(k, outside))); if (mp._1 == 0) break; } if (mp._1 == 0) break; } int val = mp._2._1; int outside = mp._2._2; //cout<<"val="<<val<<", outside="<<outside<<": "<<mp._1<<"\n"; assert(val!=-1); int B[100], R[100]; rep(i, N) B[i] = outside-1; for (int i : set) B[i] = val-1; playRound(B, R); vector<int> left, right; for (int i : set) { if (R[i] >= val) right.pb(i); else left.pb(i); } return solve2(l+left.size(), r, right); } int minValue(int N, int W) { int B[N], R[N]; rep(i, N) B[i] = 0; B[0] = 1; playRound(B, R); rep(i, N) if (R[i] <= B[i]) return i; abort(); } int maxValue(int NN, int WW) { N = NN, W = WW; vector<int> left, right; rep(i, N) perm[i] = -1; vector<int> all; rep(i, N) all.pb(i); return solve2(1, N, all); } int greaterValue(int N, int W) { return 0; } void allValues(int NN, int WW, int *P) { N = NN, W = WW; vector<int> left, right; rep(i, N) perm[i] = -1; vector<int> all; rep(i, N) all.pb(i); solve(1, N, all); rep(i, N) P[i] = perm[i]; }

컴파일 시 표준 에러 (stderr) 메시지

In file included from /usr/include/c++/7/cassert:44:0,
                 from koala.cpp:13:
koala.cpp: In function 'void solve(int, int, std::vector<int>)':
koala.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   assert(r-l+1 == set.size());
          ~~~~~~^~~~~~~~~~~~~
koala.cpp: In function 'int solve2(int, int, std::vector<int>)':
koala.cpp:97:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   assert(r-l+1 == set.size());
          ~~~~~~^~~~~~~~~~~~~
#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...