QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#332200#6300. Best Carry Player 2automac#WA 1ms4180kbC++202.7kb2024-02-19 11:35:562024-02-19 11:35:58

Judging History

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

  • [2024-02-19 11:35:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4180kb
  • [2024-02-19 11:35:56]
  • 提交

answer

#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; ++i)
#define fored(i, l, r) for(int i = (int)r; i >= (int)l; --i)
#define all(x) x.begin(), x.end()
#define el '\n'
#define d(x) cerr << #x << ' ' << x << el
#define fi first
#define se second

#define sz(a) (int) a.size()
#define pb push_back
using namespace std;

const int nax = 20;


typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;
typedef array<int, 4> a4;
typedef array<ii, 2> a2;

string x;
int k;
a2 g[nax];
deque<char> dp[nax][nax][2];
bool vis[nax][nax][2];

bool operator<(deque<char>& a, deque<char>& b){
    if(sz(a) < sz(b))return true;
    if(sz(b) > sz(a))return false;
    forn(i, sz(a)){
        if(a[i] < b[i])return true;
        if(b[i] < a[i])return false;
    }
    return false;
}

deque<char> sol(int ind, int ck, int cry){
    // d(ind);
    // d(ck);
    // d(cry);
    if(ck == k){
        return deque<char>();
    }
    if(ind == 0){
        deque<char> ans;
        if(cry == 0){
            forn(i, 37)ans.push_back('9');
            return ans;
        }
        while(ck < k){
            ans.push_back('9');
            ++ck;
        }
        return ans;
    }
    if(vis[ind][ck][cry])return dp[ind][ck][cry];
    vis[ind][ck][cry] = true;
    deque<char>& ans = dp[ind][ck][cry];
    ans = sol(ind - 1, ck, 0);
    ans.push_back('0');
    if(!(cry == 0 && x[ind - 1] == '0') && ck + g[ind][1].se <= k){
        int e = g[ind][1].fi;
        deque<char> nxt = sol(e, ck + g[ind][1].se, 1);
        fore(i, e + 1, ind - 1){
            nxt.push_back('0');
        }
        int num = 10 - cry - int(x[ind - 1] - '0');
        char c = num + '0';
        nxt.push_back(c);
        if(nxt < ans)ans = nxt;
    }
    return ans;
}

void solve(){
    cin >> x >> k;
    if(k == 0){
        cout << 0 << el;
        return;
    }
    int n = sz(x);
    int n9 = 0;
    for1(i, n){
        g[i][0].fi = i - 1;
        g[i][0].se = 0;
        g[i][1].fi = n9;
        g[i][1].se = i - n9;
        if(x[i - 1] != '9')n9 = i;
    }
    for1(ind, n){
        forn(ck, k){
            vis[ind][ck][0] = false;
            vis[ind][ck][1] = false;
        }
    }
    deque<char> ans = sol(n, 0, 0);
    bool f = false;
    for(char& c : ans){
        if(!f && c == '0')continue;
        f = true;
        cout << c;
    }
    cout << el;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt;
    cin>>tt;
    while(tt--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4180kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

0
54322
999999999987654322
9910

result:

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