QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535070#5590. Exponent Exchangestasio6WA 10ms34944kbC++141.9kb2024-08-27 19:06:382024-08-27 19:06:38

Judging History

This is the latest submission verdict.

  • [2024-08-27 19:06:38]
  • Judged
  • Verdict: WA
  • Time: 10ms
  • Memory: 34944kb
  • [2024-08-27 19:06:38]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i,a,b) for(int i = a; i < (b); i++)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define PB push_back
#define FS first
#define SD second
template<class X, class Y> void cmn(X &a, Y b) { a=min<X>(a, b); }
template<class X, class Y> void cmx(X &a, Y b) { a=max<X>(a, b); }
typedef pair<int, int> pii;
typedef vector<int> vi;

int dp[1002][2002][2];
int cyf[1002];

signed main() {
	cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
    int b, p;
    cin >> b >> p;
    for (int i = p-1; i >= 0; i--) {
        cin >> cyf[i];
    }
    for (int i = 0; i < 1000; i++) {
        for (int j = 0; j <= 2000; j++) {
            dp[i][j][0] = dp[i][j][1] = 1000000001;
        }
    }
    dp[0][1000][0] = 0;
    for (int i = 0; i < p; i++) {
        for (int j = 0; j <= 2000; j++) {
            int diff = j - 1000;
            for (int k = 0; k < 2; k++) {
                if (dp[i][j][k] >= 1000000000)
                    continue;
//                cerr << i << " " << diff << " " << k << " " << dp[i][j][k] << "\n";
                int mojcyf = (cyf[i] + k), jejcyf = (b - mojcyf);
//                cerr << mojcyf << " " << jejcyf << "\n";
                if (j + mojcyf >= 0 && j + mojcyf <= 2000)
                    cmn(dp[i+1][j+mojcyf][0], dp[i][j][k] + mojcyf);
                if (j - jejcyf >= 0 && j - jejcyf <= 2000)
                    cmn(dp[i+1][j-jejcyf][1], dp[i][j][k] + jejcyf);
            }
        }
    }
    int best = 1000000000;
    for (int j = 0; j <= 2000; j++) {
        for (int k = 0; k < 2; k++) {
            int diff = j - 1000;
//            if (dp[p][j][k] < 10)
//                cerr << diff << " " << k << " " << dp[p][j][k] << "\n";
            cmn(best, (dp[p][j][k] + abs(diff))/2);
        }
    }
    cout << best << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 34860kb

input:

10 5
4 2 7 8 6

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 3ms
memory: 34920kb

input:

2 100
1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 3ms
memory: 34920kb

input:

2 100
1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 0 1 0 0

output:

20

result:

ok single line: '20'

Test #4:

score: -100
Wrong Answer
time: 10ms
memory: 34944kb

input:

100 1000
27 21 72 90 53 34 19 36 54 48 74 65 73 50 86 92 85 84 1 57 16 40 16 97 39 62 8 11 31 4 29 56 54 29 59 22 84 65 91 25 94 96 20 30 55 62 17 19 15 40 79 75 2 74 37 53 94 69 57 21 21 39 71 2 50 12 72 98 18 84 38 81 81 11 6 69 49 52 47 25 86 10 72 74 29 16 99 28 8 9 95 62 39 25 3 20 35 20 72 82 ...

output:

0

result:

wrong answer 1st lines differ - expected: '12638', found: '0'