QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673195#5303. No Bug No Gamezwu2021016337WA 11ms144384kbC++203.1kb2024-10-24 21:01:222024-10-24 21:01:25

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 21:01:25]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:144384kb
  • [2024-10-24 21:01:22]
  • 提交

answer

#include <bits/stdc++.h> // By Lucky Ox
#define int long long
#define endl "\n"
#define pii pair<int, int>
#define PI atan(1.0) * 4
using namespace std;
using i128 = __int128;
typedef unsigned long long ull;
const int mod = LONG_LONG_MAX, INF = 0x3f3f3f3f3f3f3f3f;
int P(int x, int p){ return (x % p + p) % p; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int len_10(int x) { int len = 0; while(x) { x /= 10; len ++ ; } return len; }
int q_pow(int a, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * a % p; k >>= 1; a = a * a % p; } return res; }
int to_int(string s) { int val = 0; for(int i = 0; i < (int)s.size(); i ++ ){val *= 10; val += s[i] - '0';}return val;}//注意:s是空串也会返回0
i128 read() { i128 x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar(); } return x; } //i128输入
void print(i128 x) {if(x > 9) print(x / 10); putchar(x % 10 + '0'); }//i128输出
//用__lg()来求一个数二进制下的位数 返回的len 表示这个数是[0, 1, ...., len] 比如10 __lg(10) = 3, 1010 [3, 2, 1, 0]
//__builtin_popcountll(int x) 求二进制下x中1的数量 __buitlin_ctzll(int x) 求二进制下末尾0的个数
//(n & (1 << i))的值可能会是1, 2, 4...... (n >> i) & 1的值一定是1
//将x转换成[1, n]中对应的数 (x - 1) % n + 1
//bool __ED__;
const int N = 3e3 + 10;
int n, k;
int p[N], w[N][N];
int dp[N][N], vis[N]; //前i个数, 和为j的最大解
//bool __ST__;
void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i ++ ) {
        cin >> p[i];
        for(int j = 1; j <= p[i]; j ++ ) {
            cin >> w[i][j];
        }
    }

    dp[1][p[1]] = w[1][p[1]];
    for(int i = 2; i <= n; i ++ ) {
        for(int j = 1; j <= k; j ++ ) {
            dp[i][j] = dp[i - 1][j];
            if(j >= p[i] && dp[i - 1][j - p[i]]) dp[i][j] = max(dp[i][j], dp[i - 1][j - p[i]] + w[i][p[i]]);
        }
    }
    // for(int i = 1; i <= n; i ++ ) 
    //     for(int j = 1; j <= k; j ++ ) cout << dp[i][j] << " \n"[j == k];
    int ans = 0, sum = 0;
    for(int i = k; i >= 0; i -- ) {
        if(dp[n][i] > ans) {
            ans = dp[n][i];
            sum = i;
        } 
    }
    //cout << ans << " " << sum << endl;

    int tmp = sum;
    for(int i = n; i >= 1; i -- ) {
        if(dp[i - 1][tmp - p[i]] + w[i][p[i]] == dp[i][tmp]) {
            vis[i] = 1;
            tmp -= p[i];
        }
        //cout << tmp << " \n"[i == 1];
    }
    //for(int i = 1; i <= n; i ++ ) cout << vis[i] << " \n"[i == n];
    int maxn = 0;
    for(int i = 1; i <= n; i ++ ) {
        int val = 0;
        if(!vis[i]) {
            val += w[i][k - sum];
        }
        maxn = max(maxn, val);
    }
    ans = ans + maxn;
    cout << ans << endl;
}

signed main() {
    //cerr << abs(&__ED__-&__ST__) / (1024.0 * 1024.0) <<" MiB\n";
    ios::sync_with_stdio(0);cin.tie(0);
    cout << fixed << setprecision(10);
    int T = 1;
    //cin >> T;
    while (T -- ) solve();
    return 0;
}
/*
4 5
2 1 2
2 1 1
2 3 1
2 1 3
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

input:

4 5
2 1 3
2 1 1
2 3 1
2 1 3

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 144384kb

input:

3000 3000
10 70562 30723 79371 82224 63977 3362 26909 96449 48163 66159
4 18007 33590 80674 91139
4 10304 31694 70745 50656
10 63090 17226 13187 73881 38137 15237 55750 82751 75854 39658
8 95640 66120 87735 36388 44046 92415 6952 94772
9 60565 27904 98726 87052 35768 25453 14563 34273 92501
10 66332...

output:

68132112

result:

wrong answer 1st numbers differ - expected: '68279788', found: '68132112'