QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#456474#8769. Champernowne Substringucup-team2307WA 117ms3564kbC++204.5kb2024-06-28 04:13:482024-06-28 04:13:48

Judging History

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

  • [2024-06-28 04:13:48]
  • 评测
  • 测评结果:WA
  • 用时:117ms
  • 内存:3564kb
  • [2024-06-28 04:13:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
//#define int ll
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back

const int MOD=998244353;

string inc(string s)
{
    for(int i=sz(s)-1;i>=0;i--)
        if(s[i]=='9')
            s[i]='0';
        else
        {
            s[i]++;
            break;
        }
    return s;
}

string dec(string s)
{
    for(int i=sz(s)-1;i>=0;i--)
        if(s[i]=='0')
            s[i]='9';
        else
        {
            s[i]--;
            break;
        }
    return s;
}

__int128 parse(string s)
{
    __int128 res=0;
    for(char c:s)
        res=res*10+(c-'0');
    return res;
}

#define NONE {1e9,"",0}

#define check(var,val) if(var!='?'&&var!=val) return NONE; else var=val

tuple<int,string,int> check_dig(string s,int len,int add_pref,int dig,int suf,int ind)
{
    s=string(add_pref,'?')+s;
    while(s.size()%len)
        s+='?';
    vector<string> nums;
    for(int i=0;i<s.size();i+=len)
        nums.pb(s.substr(i,len));
    string last(len,'0');
    for(int i=ind;i<nums.size();i++)
    {
        if(i<0) continue;
        for(int j=len-suf;j<len;j++)
            check(nums[i][j],last[j]);
        last=inc(last);
    }
    last=string(len,'9');
    for(int i=ind-1;i>=0;i--)
    {
        if(i>=sz(nums)) continue;
        for(int j=len-suf;j<len;j++)
            check(nums[i][j],last[j]);
        last=dec(last);
    }
    __int128 pw=1;
    for(int i=0;i<suf;i++)
        pw*=10;
    for(int i=0;i<nums.size();i++)
    {
        if(i%pw==ind%pw)
            dig=(dig+1)%10;
        check(nums[i][len-suf-1],'0'+dig);
    }
    for(int j=0;j<len-suf-1;j++)
    {
        char cur='?';
        for(int i=0;i<nums.size();i++)
        {
            if(cur=='?') cur=nums[i][j];
            check(nums[i][j],cur);
        }
        if(cur=='?') cur=(j==0?'1':'0');
        for(int i=0;i<nums.size();i++)
        {
            if(cur=='?') cur=nums[i][j];
            check(nums[i][j],cur);
        }
    }
    for(int i=0;i<nums.size();i++)
        if(nums[i][0]=='0')
            return NONE;
    return {len,nums[0],add_pref};
}

tuple<int,string,int> check_inc(string s,int len,int add_pref,int cnt_same)
{
    s=string(add_pref,'?')+s;
    vector<string> nums;
    for(int i=0;i<s.size();i+=len) {
        if(nums.size()==cnt_same)
            len++;
        nums.pb(s.substr(i, len));
    }
    if(nums.size()<=cnt_same)
        return NONE;
    while(nums.back().size()<len)
        nums.back()+='?';
    len--;
    string last="1"+string(len,'0');
    for(int i=cnt_same;i<nums.size();i++)
    {
        if(i<0) continue;
        for(int j=0;j<sz(last);j++)
            check(nums[i][j],last[j]);
        last=inc(last);
    }
    last=string(len,'9');
    for(int i=cnt_same-1;i>=0;i--)
    {
        if(i>=sz(nums)) continue;
        for(int j=0;j<len;j++)
            check(nums[i][j],last[j]);
        last=dec(last);
    }
    for(int i=0;i<nums.size();i++)
        if(nums[i][0]=='0')
            return NONE;
    return {nums[0].size(),nums[0],add_pref};
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        tuple<int,string,int> ans=NONE;
        for(int len=1;len<=s.size()+1;len++) {
            if(get<0>(ans)<len)
                break;
            for (int add_pref = 0; add_pref < len; add_pref++) {
                for (int dig = 0; dig <= 9; dig++)
                    for (int suf = 0; suf < len; suf++)
                        for (int ind = 0; ind <= s.size() / len + 2; ind++)
                            ans = min(ans, check_dig(s, len, add_pref, dig, suf, ind));
                for (int cnt_same = 1; cnt_same <= s.size() + 1; cnt_same++)
                    ans = min(ans, check_inc(s, len, add_pref, cnt_same));
            }
        }
        auto[len,num,skip]=ans;
//        cout<<len<<" "<<num<<" "<<skip<<" -> ";
        __int128 res=0,i=1,pw=10;
        while(i<len)
        {
            res+=(pw-pw/10)*i;
            i++;
            pw*=10;
        }
        res+=(parse(num)-pw/10)*len;
        res+=skip;
        res++;
        cout<<int(res%MOD)<<"\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 3520kb

input:

9
0
???1
121
1?1?1
??5?54?50?5?505?65?5
000000000000
?2222222
?3????????9??8???????1??0
9?9??0????????????2

output:

11
7
14
10
314159
796889014
7777
8058869
38886

result:

ok 9 lines

Test #2:

score: -100
Wrong Answer
time: 117ms
memory: 3564kb

input:

10
0000000000000000000000000
0000000?002100000000000?0
6999?999?999999989?999999
0???0?1000?0??000?????0?1
9??9?999998?9?999999100?0
96?9997999?8999991????010
99?99??999999999??????99?
?0?0000?00000000?0210?0?0
99?999?999?99?9??999?9?9?
9?????9?99?99??9??99??9??

output:

545305036
574985081
788888865
5889591
690644517
488873
68888876
830780534
5888885
38880

result:

wrong answer 5th lines differ - expected: '902934046', found: '690644517'