Submission #718967

#TimeUsernameProblemLanguageResultExecution timeMemory
718967KalashnikovLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
1589 ms994708 KiB
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; const int N = 500+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7 , P = 6547; int a[N], b[N]; double dp[N][N][N]; void mini(double &a, double b) { a = min(a, b); } void solve(int tc) { int n , k; cin >> n >> k; vector<pair<int,int>> vec; for(int i = 1; i <= n; i ++) { cin >> a[i] >> b[i]; if(b[i] == -1) b[i] = inf; vec.push_back({b[i] , a[i]}); } sort(all(vec)); for(int i = 1; i <= n; i ++) { a[i] = vec[i-1].S; b[i] = vec[i-1].F; } for(int i = 0; i <= n; i ++) { for(int j = 0; j <= n; j ++) { for(int k = 0; k <= n; k ++) { dp[i][j][k] = INF; } } } for(int i = 0; i <= n; i ++) dp[i][0][0] = 0; double ans = INF; for(int l = 0; l <= n; l ++) { // в конце сторонников for(int i = 0; i < n; i ++) { for(int j = 0; j <= i; j ++) { mini(dp[i+1][j][l], dp[i][j][l]); mini(dp[i+1][j+1][l], dp[i][j][l] + a[i+1]/double(l+1)); if(i == j) for(int x = 0; x <= min(j, l); x ++) { mini(dp[i+1][j][x], dp[i][j][x]); mini(dp[i+1][j+1][x], dp[i][j][x] + a[i+1]/double(l+1)); if(b[i+1] != inf) mini(dp[i+1][j+1][x+1], dp[i][j][x] + b[i+1]/double(x+1)); } } } ans = min(ans, dp[n][k][l]); } cout << fixed << setprecision(6) << ans; } /* */ main() { ios; int tt = 1 , tc = 0; // cin >> tt; while(tt --) { solve(++tc); } return 0; }

Compilation message (stderr)

Main.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main() {
      | ^~~~
#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...