QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718340#3322. Array of DiscordqwerasdfWA 0ms3552kbC++201.9kb2024-11-06 20:17:442024-11-06 20:17:44

Judging History

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

  • [2024-11-06 20:17:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-11-06 20:17:44]
  • 提交

answer

//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder; //https://github.com/atcoder/ac-library

#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define bit(n, k) ((n >> k) & 1)
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> pii;

bool check(ll x, ll y){
    string s=to_string(x), t=to_string(y);
    if((int)s.length()!=(int)t.length()){
        return false;
    }
    else{
        int n=(int)s.length();
        if(n==1){
            if(y==9){
                if(x==0)return false;
                return true;
            }
            else{
                return true;
            }
        }
        if(s[0]==t[0]){
        }
        if(s[0]!='1')return true;
        // s[0]=='1'
        if(t[0]!='9')return true;
        s[0]=t[0];
        return stoll(s)>stoll(t);
    }
}

void test_case(int tt){
    int n; cin>>n;
    int ok=-1;
    vector<ll> a(n);
    rep(i,0,n)cin>>a[i];
    rep(i,0,n-1){
        if(check(a[i],a[i+1])){
            ok=i;
            break;
        }
    }
    if(ok==-1){
        cout<<"impossible\n";
        return;
    }
    ll x=a[ok], y=a[ok+1];
    string s=to_string(x), t=to_string(y);
    int m=(int)s.length();
    if(m==1){
        a[ok+1]=y;
    }
    else{
        if(s[0]==t[0]){
            if(s[0]!='9')s[0]='9';
            else t[0]='1';
        }
        else{
            if(s[0]!='1'){
                t[0]='1';
            }
            else if(t[0]!='9'){
                s[0]='9';
            }
            else{
                s[0]=t[0];
            }
        }
        a[ok]=stoll(s);
        a[ok+1]=stoll(t);
    }
    rep(i,0,n)cout<<a[i]<<' ';
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    //cin>>t;
    rep(i, 1, t + 1)
    {
        test_case(i);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

10
0 1 2 3 4 5 6 7 8 9

output:

0 1 2 3 4 5 6 7 8 9 

result:

wrong answer 1st lines differ - expected: '9 1 2 3 4 5 6 7 8 9', found: '0 1 2 3 4 5 6 7 8 9 '