QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344332#8251. Missing NumberHaidy_Yasser#WA 23ms3548kbC++142.1kb2024-03-04 02:33:492024-03-04 02:33:49

Judging History

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

  • [2024-03-04 02:33:49]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:3548kb
  • [2024-03-04 02:33:49]
  • 提交

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;
        for(int i = 0; i < n; i += l){
            if(prev && allNine(to_string(prev)))
                l++;
            if(i + l <= n){
                string sub = s.substr(i, l);
                // cout << sub << " ";
                if(!prev)
                    prev = stoi(sub);
                else{
                    int cur = stoi(sub);
                    if(cur-prev > 2 || cur-prev == 0){
                        ok = false;
                        break;
                    }
                    if(cur-prev == 2){
                        cnt++;
                        missing = cur - 1;
                    }
                    prev = cur;
                    if(cnt > 1){
                        ok = false;
                        break;
                    }
                }
            }
            else{
                ok = false;
                break;
            }
        }
        if(ok && cnt <= 1){
            cout << cnt << endl;
            cout << missing << endl;
            return;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3544kb

input:

1
891112

output:

1
10

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 23ms
memory: 3548kb

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 211th lines differ - expected: '2', found: '0'