QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#332158#6307. Chase Game 2automac#Compile Error//C++203.0kb2024-02-19 10:57:392024-02-19 10:57:39

Judging History

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

  • [2024-02-19 10:57:39]
  • 评测
  • [2024-02-19 10:57:39]
  • 提交

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){
    if(ck == k){
        return deque<char>();
    }
    if(ind == 0){
        deque<char> ans;
        assert(cry == 1);
        while(ck < k){
            ans.push_front('9');
            ++ck;
        }
        return ans;
    }
    if(vis[ind][ck])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<int> nxt = sol(e, ck + g[ind][1].se, 1);
        int num = 10 - cry - int(x[ind - 1] - '0');
        char c = num + '0';
        ans.push_front(c);
        --ind;
        while(ind > e){
            ans.push_front('0');
            --ind;
        }
    }
}

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;
    }
    int ind = n;
    int cry = 0;
    int ck = 0;
    deque<char> ans;
    while(ind > 0){
        if(ck == k)break;
        if(cry == 0 && x[ind - 1] == 0 || ck + g[ind][1].se > k){
            ans.push_front('0');
            --ind;
            cry = 0;
            continue;
        }
        ck += g[ind][1].se;
        int e = g[ind][1].fi;
        int num = 10 - cry - int(x[ind - 1] - '0');
        char c = num + '0';
        ans.push_front(c);
        --ind;
        while(ind > e){
            ans.push_front('0');
            --ind;
        }
        cry = 1;
        continue;
    }
    while(ck < k){
        assert(cry == 1);
        ans.push_front('9');
        ++ck;
    }
    for(char& c : ans)cout << c;
    cout << el;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tt;
    cin>>tt;
    while(tt--){
        solve();
    }
}

Details

answer.code: In function ‘std::deque<char> sol(int, int, int)’:
answer.code:62:29: error: conversion from ‘deque<char>’ to non-scalar type ‘deque<int>’ requested
   62 |         deque<int> nxt = sol(e, ck + g[ind][1].se, 1);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~