QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535040#5590. Exponent Exchangestasio6WA 6ms34988kbC++141.6kb2024-08-27 18:50:172024-08-27 18:50:18

Judging History

This is the latest submission verdict.

  • [2024-08-27 18:50:18]
  • Judged
  • Verdict: WA
  • Time: 6ms
  • Memory: 34988kb
  • [2024-08-27 18:50:17]
  • 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;
                int mojcyf = cyf[i] + k, jejcyf = b - mojcyf;
                if (j + mojcyf >= 0 && j + mojcyf <= 2000)
                    dp[i+1][j+mojcyf][0] = dp[i][j][k] + mojcyf;
                if (j - jejcyf >= 0 && j - jejcyf <= 2000)
                    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;
            cmn(best, (dp[p][j][k] + abs(diff))/2);
        }
    }
    cout << best << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 34936kb

input:

10 5
4 2 7 8 6

output:

7

result:

ok single line: '7'

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 34988kb

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:

28

result:

wrong answer 1st lines differ - expected: '19', found: '28'