QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344335#8251. Missing NumberHaidy_Yasser#WA 72ms3604kbC++142.3kb2024-03-04 02:58:242024-03-04 02:58:25

Judging History

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

  • [2024-03-04 02:58:25]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:3604kb
  • [2024-03-04 02:58:24]
  • 提交

answer

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

#define pb push_back
#define sz(x) int(x.size())
#define all(vec) vec.begin(), vec.end()
#define rall(vec) vec.rbegin(), vec.rend()
#define cin(v) for (auto& cn : v)  cin >> cn;
#define cout(v) for (auto &cn : v) cout << cn << " ";
#define MOD int(1e9+7)
// #define endl "\n"
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

void Haidy()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#endif
}
 
void solve();
int main()
{
    Haidy();
    int t = 1;
    cin >> t;
    for(int i = 1;i<=t; i++)
    {
        solve();
    }
    return 0;
}
// int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
// int dy[] = {1, -1, 0, 0, 1, -1, -1, 1};

bool allNine(string s)
{
    for(auto &c : s)
        if(c != '9')
            return false;
    return true;
}

void solve()
{
    string s;
    cin >> s;
    int n = sz(s);
    for(int len = 1; len <= 5; len++){
        int l = len;
        bool ok = true;
        int prev = 0, cnt = 0, missing = 0, cnt2 = 0;
        for(int i = 0; i < n; i += l){
            if(allNine(to_string(prev)))
                l++;
            if(i + l <= n){
                string sub = s.substr(i, l);
                if(!prev)
                    prev = stoi(sub);
                else{
                    int cur = stoi(sub);
                    if(cur < prev){
                        sub = s.substr(i, l+1);
                        l++;    
                        cur = stoi(sub);
                    }
                    if(cur-prev > 1){
                        cnt++;
                        cnt2 = cur - prev - 1;
                        missing = prev + 1;
                    }
                    if(cnt > 1 || cur - prev == 0 || sub[0] == '0')
                        ok = false;
                    prev = cur;
                }
            }
            else{
                // cout << i << " " << l << "\n" ; 
                ok = false;
                break;
            }
            
        }
            
        if(ok && cnt <= 1){
            cout << cnt2 << endl;
            for(int i = 0; i < cnt2; i++){
                cout << missing+i << " ";
            }
            return;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
891112

output:

1
10 

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 72ms
memory: 3604kb

input:

31408
787187871978720787217872278723787247872678727
8787287874878758787687877
834918349283493834958349683497
295982959929600296012960229604
602160226023602460256027602860296030
504545045550456504575045850459504605046250463
17937179381794017941
5226152262522635226552266
304693047030471304733047430475...

output:

1
78725 1
87873 1
83494 1
29603 1
6026 1
50461 1
17939 1
52264 1
30472 1
71484 1
44832 1
88042 1
75634 1
63756 1
65055 1
66515 1
26238 1
29009 1
45270 1
11194 1
75204 1
74784 1
72747 1
29546 1
81791 1
11504 1
73091 1
15640 1
36200 1
47814 1
82261 1
3667 1
6949 1
81711 1
32272 1
74387 1
40400 1
76903...

result:

wrong answer 2nd lines differ - expected: '78725', found: '78725 1'