답안 #528032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528032 2022-02-19T03:26:31 Z amukkalir Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
2037 ms 496400 KB
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
 
#define prn printf
#define scn scanf
#define pii pair<int,int> 
#define fi first 
#define se second 

const int nax = 500;  
const int inf = 1e9; 

int n,k; 
double memo[nax+5][nax+5][nax+5]; 
pii a[nax+5]; 

double dp(int idx, int col, int rem) {
    if(rem == 0) return 0; 
    if(idx == n) return inf; 

    double &ret = memo[idx][col][rem]; 
    if(ret!=0) return ret; 

    ret = dp(idx+1, col, rem); // ga ambil 
    ret = min(ret, (double)a[idx].se/col + dp(idx+1,col,rem-1)); 
    if(a[idx].fi != inf) ret = min(ret, (double)a[idx].fi/col + dp(idx+1, col+1, rem-1)); 

   // cerr << idx << " " << col << " " << rem << " = " << ret << endl; 
    return ret; 
}

signed main () {
    scn("%d%d", &n, &k); 

    for(int i=0; i<n; i++) {
        scn("%d%d", &a[i].se, &a[i].fi);
        if(a[i].fi == -1) a[i].fi = inf; 
    }
    sort(a, a+n); 

    double ans = dp(0, 1, k); 
    prn("%f", ans); 
}

/*
dp(i,j,k) = time minimum untuk visit k kota up to index i 
ddn j collaboratior 

dp(i,j,0) = 0

ambil b 
dp(i+1, j+1, k-1) + b[i]
ambil a 
dp(i+1, j, k-1) + a[i]
ga ambil 
dp(i+1, j+1, k)
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scn("%d%d", &n, &k);
      |        ^
Main.cpp:37:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scn("%d%d", &a[i].se, &a[i].fi);
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4428 KB Output is correct
6 Correct 7 ms 4684 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 9 ms 5156 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 10 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4428 KB Output is correct
6 Correct 7 ms 4684 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 9 ms 5156 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 10 ms 5196 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 336 ms 254032 KB Output is correct
13 Correct 286 ms 254044 KB Output is correct
14 Correct 189 ms 180092 KB Output is correct
15 Correct 1492 ms 451744 KB Output is correct
16 Correct 1102 ms 413272 KB Output is correct
17 Correct 329 ms 175936 KB Output is correct
18 Correct 1928 ms 496400 KB Output is correct
19 Correct 1354 ms 420324 KB Output is correct
20 Correct 390 ms 167792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2037 ms 496356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4428 KB Output is correct
6 Correct 7 ms 4684 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 9 ms 5156 KB Output is correct
9 Correct 5 ms 5196 KB Output is correct
10 Correct 10 ms 5196 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 336 ms 254032 KB Output is correct
13 Correct 286 ms 254044 KB Output is correct
14 Correct 189 ms 180092 KB Output is correct
15 Correct 1492 ms 451744 KB Output is correct
16 Correct 1102 ms 413272 KB Output is correct
17 Correct 329 ms 175936 KB Output is correct
18 Correct 1928 ms 496400 KB Output is correct
19 Correct 1354 ms 420324 KB Output is correct
20 Correct 390 ms 167792 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Halted 0 ms 0 KB -