QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734688 | #9285. Construct The Integer | N_z_ | AC ✓ | 0ms | 3768kb | C++23 | 7.6kb | 2024-11-11 14:11:03 | 2024-11-11 14:11:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
void init();void solve(int tc);
main()
{
init();int t=1;
cin>>t;
for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
long long calc(const vector<int>&v)
{
// dbg(v);
long long g=0;
for(auto a:v)
for(auto b:v)
g=__gcd(g,9ll*(a-b));
g=abs(g);
long long nv=0;
for(auto a:v)
nv=nv*10+a;
g=__gcd(g,nv);
// dbg(g);
return g;
}
// #define endl ','
// #define cout cerr
long long n;
vector<int>v;
long long nr,rr=0;
bool dfs(int u,int sum)
{
if(nr!=-1&&nr<rr)return 0;
if(u*9<sum)return 0;
if((v.size()>2?v.back():0)*u>sum)return 0;
if(u==0)
{
if(calc(v)==n){if(nr==-1||nr>rr)nr=rr;return 1;}
return 0;
}
for(int x=v.size()==0?1:v.size()==1?0:v.back();x<=9;x++)
{
v.emplace_back(x);
rr=rr*10+x;
bool res=dfs(u-1,sum-x);
v.pop_back();
rr/=10;
if(res)return 1;
}
return 0;
}
constexpr long long ans[]={0,1,2,3,4,5,6,7,8,9,-1,11,48,-1,-1,5055,-1,-1,288,-1,-1,7077,22,-1,8088,-1,-1,3699,-1,-1,-1,-1,-1,33,-1,-1,48888,-1,-1,-1,-1,-1,-1,-1,44,5055555555,-1,-1,-1,-1,-1,-1,-1,-1,222888888,55,-1,-1,-1,-1,-1,-1,-1,111888,-1,-1,66,-1,-1,-1,-1,-1,8088888888,-1,-1,-1,-1,77,-1,-1,-1,9099999999};
void solve([[maybe_unused]]int tc)
{
// n=tc;
cin>>n;
{
vector<int>v;
long long vv=n;
while(vv)v.emplace_back(vv%10),vv/=10;
for(auto q:v)
if(q!=v[0])goto fail;
cout<<n<<endl;
return;
fail:;
}
// if(n%3!=0){cout<<-1<<endl;return;}
// if(n<=27){cout<<ans[n]<<endl;return;}
// if(n%9!=0){cout<<-1<<endl;return;}
if(n<=81){cout<<ans[n]<<endl;return;}
nr=-1;
// for(int y=9;y<=162;y+=9)
// for(int x=1;x<=18;x++)
// if(dfs(x,y))break;
cout<<nr<<endl;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
2 12 2021
output:
48 -1
result:
ok 2 number(s): "48 -1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
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 33333333333333333 -1 -1 33333333333333 7777777777777777 -1 -1 -1 888 -1 4444444444 -1 3333333333333333 88888888 888888888888 88 -1 3333333333333 -1 555 -1 48888 222222222222 -1 -1 -1 -1 -1 -1 -1 11 -1 -1 55555555555555555
result:
ok 50 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
50 841731922341882973 172755266467187037 129493702112701195 90 273793122414069242 593694707008455288 502545216673419533 721595990997982386 93377610984612549 87 863812025013802109 234122432773362066 123027939432443575 88888 47 222222222222222222 852841820206347862 74 423472610938208849 94 15762310812...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 88888 -1 222222222222222222 -1 -1 -1 -1 -1 -1 -1 22222222 -1 -1 -1 -1 -1 -1 -1 -1 333333333333333 -1 -1 -1 1111111111111111 -1 -1 -1 4 333333333 -1 33333333 -1 1 444444444444444444 5055 -1 4444444444444444
result:
ok 50 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
50 66666666 89 11111111111111111 89013034181000726 33 285627919192884437 8888888888 425171425350891250 71 7 987944414171602593 301305598619697018 193193702519217107 413499651741453076 476551385483571548 13 668044926137832393 66666666666666 536187734191891003 386045016440405474 592806051753396502 805...
output:
66666666 -1 11111111111111111 -1 33 -1 8888888888 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 66666666666666 -1 -1 -1 -1 4444444 666666666666666 -1 -1 -1 666666666666666666 -1 -1 -1 -1 -1 33 -1 -1 -1 -1 77777777777 -1 -1 8888888 -1 -1 -1 -1 -1 -1 -1 66
result:
ok 50 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
50 21839873092357856 640219260799980486 522525742014723888 725988133037119616 290913044663852094 555555 333 85 11111111 631169318889705610 555555555555 69 323842199157642120 333333333333333333 78 4444444444444 99 11111111111 174059246927999752 377574503599716306 777777777 45 77777777777777 471255439...
output:
-1 -1 -1 -1 -1 555555 333 -1 11111111 -1 555555555555 -1 -1 333333333333333333 -1 4444444444444 99 11111111111 -1 -1 777777777 5055555555 77777777777777 -1 -1 -1 -1 -1 666 -1 3699 11111 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 222222 777
result:
ok 50 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
50 134845565732593935 935387048910748709 664860202421625603 111111111111 94225248889089695 879054556667480931 83 256931203846046588 92 3333333333 643572951492602142 49 822981260158260819 82526944128792584 77 179102579989215254 444444444444444 903288965370689433 799584023203226863 495718727325977077 ...
output:
-1 -1 -1 111111111111 -1 -1 -1 -1 -1 3333333333 -1 -1 -1 -1 77 -1 444444444444444 -1 -1 -1 9 55555555555 66666666666 -1 -1 7077 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 444444444444 111111111111111111 -1 777777 -1 1111111 -1 -1 -1 5555555 -1 -1
result:
ok 50 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
50 521060787741107580 23 676105575462225385 381451598031262925 163853609803189968 6666666666 444444444 5413279537561410 8888 627586599810900678 26 42 55555555555555 43 916143781173401889 84324828731964774 57 502764983190081253 563324731189331234 53 993638134797830048 3 52966605322057444 333333333333...
output:
-1 -1 -1 -1 -1 6666666666 444444444 -1 8888 -1 -1 -1 55555555555555 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 333333333333 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11111111111111 -1 -1 -1 44444444 -1 -1 -1
result:
ok 50 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
50 888888888888888 56 877835694720649559 952720572201731456 335408917861649366 66666 2222222222222 2222222222222222 60 787629613935422754 776076510839296560 630192867080657053 88888888888 77 371026816893229896 540950482791116710 1111 438538728083004091 1111111111111 692477168467510300 14875591187121...
output:
888888888888888 -1 -1 -1 -1 66666 2222222222222 2222222222222222 -1 -1 -1 -1 88888888888 77 -1 -1 1111 -1 1111111111111 -1 -1 -1 111 444 -1 44444444444 -1 -1 -1 55555555 222 7777777777 -1 555555555555555555 -1 -1 -1 66 -1 3333 -1 -1 77777777 -1 22222222222 -1 -1 -1 8088888888 -1
result:
ok 50 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
50 59 51 661302813816248549 22 192583020404011827 17 44444444444444 91 586662754350034562 398400101471708497 101765673897273715 950257034940091202 675282347327966568 262324075672299484 55 116841977139981012 907267074306890738 731741654713115120 33333333333 95 111111111 49465410047628729 676526945279...
output:
-1 -1 -1 22 -1 -1 44444444444444 -1 -1 -1 -1 -1 -1 -1 55 -1 -1 -1 33333333333 -1 111111111 -1 -1 88888888888888 -1 666666666666 -1 7777 -1 -1 -1 666666666 -1 -1 -1 -1 -1 -1 6666666666666 -1 -1 -1 6 -1 3333333 -1 -1 -1 -1 5
result:
ok 50 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
50 52 575309381208032699 5555555555555 266726083774034829 542826291792345757 7777777 851387910588959345 769483004587345130 66666666666666666 444444 753084815602287766 21314793613364329 555555555555555 5555 55555 802650828045480305 59132663174616906 18 107332661275127473 33333 22222222222222 70482262...
output:
-1 -1 5555555555555 -1 -1 7777777 -1 -1 66666666666666666 444444 -1 -1 555555555555555 5555 55555 -1 -1 288 -1 33333 22222222222222 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 44444 -1 -1 -1 -1 -1 555555555 -1 -1 8888888888888888 -1 -1 -1 -1 -1 -1 -1
result:
ok 50 numbers
Test #11:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
50 777777777777777 838885201040309576 7777777777777 349993004923079131 961905130001849922 44 888888888 494205937842636532 88 665229069533206603 676042795298310688 704087678909665196 148049062628894820 81 58 615812229161736595 758551024807498420 819875141880896223 922348607469188267 8888888888888 168...
output:
777777777777777 -1 7777777777777 -1 -1 44 888888888 -1 88 -1 -1 -1 -1 9099999999 -1 -1 -1 -1 -1 8888888888888 -1 -1 -1 -1 2222 -1 -1 888888888888888888 -1 5555555555 5555555555555555 -1 222888888 -1 -1 -1 -1 -1 -1 111111111111111 -1 777777777777777777 -1 -1 77777 -1 99 -1 55 -1
result:
ok 50 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
34 222222222222222 75758645129816374 222222222 126848078891669023 6666 2222222 777777777777 559963841661127373 44444444444444444 594688604155375033 433879482817020740 888888 507706624286986629 2222222222 202119862215209290 39 578223540024980336 4444 8 6666666666666666 585335723211047994 777777777777...
output:
222222222222222 -1 222222222 -1 6666 2222222 777777777777 -1 44444444444444444 -1 -1 888888 -1 2222222222 -1 -1 -1 4444 8 6666666666666666 -1 77777777777777777 -1 88888888888888888 1111111111 -1 22222222222222222 111111 -1 -1 -1 -1 -1 111888
result:
ok 34 numbers
Extra Test:
score: 0
Extra Test Passed