QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563711#9285. Construct The Integerzjy0001WA 148ms4016kbC++171.1kb2024-09-14 15:20:252024-09-14 15:20:25

Judging History

This is the latest submission verdict.

  • [2024-09-14 15:20:25]
  • Judged
  • Verdict: WA
  • Time: 148ms
  • Memory: 4016kb
  • [2024-09-14 15:20:25]
  • Submitted

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
map<LL,int>ans;
int a[10],f[100000];
inline bool chk(int n){
    int c=n%10;
    while(n/=10)if(n%10!=c)return 0;
    return 1;
}
inline void dfs(int x){
    if(x==5){
        vector<int>d;
        do{
            int x=0;for(int i=0;i<5;++i)x=x*10+a[i];
            d.emplace_back(x);
        }while(next_permutation(a,a+5));
        sort(a,a+5);
        for(auto i:d)for(auto j:d)
            if(to_string(i).length()>=to_string(j).length())
                f[i]=__gcd(f[i],j);
    }
    else for(int i=x?a[x-1]:0;i<10;++i)a[x]=i,dfs(x+1);
}
inline void init(){
    iota(f+1,f+100000,1);
    dfs(0);
    for(int i=1;i<100000;++i)
        if(!ans.count(f[i]))ans[f[i]]=i;
        else ans[f[i]]=min(ans[f[i]],i);
}
inline void MAIN(){
    LL n;cin>>n;
    if(chk(n))cout<<n<<'\n';
    else cout<<(ans.count(n)?ans[n]:-1)<<'\n';
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    init();
    int t=1;cin>>t;while(t--)MAIN();
    return 0;
}
/*
*/

详细

Test #1:

score: 100
Accepted
time: 148ms
memory: 4016kb

input:

2
12
2021

output:

48
-1

result:

ok 2 number(s): "48 -1"

Test #2:

score: -100
Wrong Answer
time: 147ms
memory: 3944kb

input:

50
162281868021198482
843590795441798975
22222
149588437607469906
802011151087104980
6059547534408460
24
666666
2
76
29
44
6666666
333333
694875412087041404
203911016125660313
33333333333333333
621646568444724049
363434583954291856
33333333333333
7777777777777777
308242055812053607
65243634304254533...

output:

-1
-1
22222
-1
-1
-1
8088
666666
2
-1
-1
44
6666666
333333
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
888
-1
-1
-1
-1
88888888
-1
88
-1
-1
-1
555
-1
48888
-1
-1
-1
-1
-1
-1
-1
-1
11
-1
-1
-1

result:

wrong answer 17th numbers differ - expected: '33333333333333333', found: '-1'