답안 #444198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444198 2021-07-13T10:32:49 Z prvocislo 조교 (CEOI16_popeala) C++17
100 / 100
375 ms 10436 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int inf = 2e9 + 5;
void upd(int &a, int b) { a = min(a, b); }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t, s;
    cin >> n >> t >> s;
    vector<int> pf(t+1, 0);
    for (int i = 1, x; i <= t; i++) cin >> x, pf[i] = pf[i-1] + x;
    vector<vector<int> > h(t+1, vector<int>(n+1, 0));
    for (int i = 0; i < n; i++)
    {
        string s; cin >> s;
        for (int j = 1; j <= t; j++)
        {
            h[j][i] = h[j-1][i];
            if (s[j-1] == '0') h[j][i] = j;
        }
    }
    for (int i = 1; i <= t; i++)
    {
        h[i][n] = i;
        sort(h[i].begin(), h[i].end());
    }
    vector<vector<int> > dp(s+1, vector<int>(t+1, inf));
    dp[0][0] = 0;
    for (int i = 1; i <= s; i++)
    {
        vector<int> best(n+1, inf);
        for (int j = 1; j <= t; j++)
        {
            for (int k = 0; k <= n; k++) 
            {
                for (int l = h[j-1][k]; l < h[j][k]; l++)
                    upd(best[k], dp[i-1][l]-pf[l]*k);
                upd(dp[i][j], best[k]+pf[j]*k);
            }
        }
        cout << dp[i][t] << endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 460 KB Output is correct
2 Correct 9 ms 456 KB Output is correct
3 Correct 10 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 1228 KB Output is correct
2 Correct 66 ms 1812 KB Output is correct
3 Correct 77 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 10 ms 460 KB Output is correct
4 Correct 9 ms 456 KB Output is correct
5 Correct 10 ms 460 KB Output is correct
6 Correct 47 ms 1228 KB Output is correct
7 Correct 66 ms 1812 KB Output is correct
8 Correct 77 ms 2252 KB Output is correct
9 Correct 105 ms 3600 KB Output is correct
10 Correct 166 ms 4600 KB Output is correct
11 Correct 313 ms 10140 KB Output is correct
12 Correct 313 ms 10360 KB Output is correct
13 Correct 375 ms 10384 KB Output is correct
14 Correct 367 ms 10308 KB Output is correct
15 Correct 367 ms 10436 KB Output is correct