UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213379#2355. Digitnullptr_qwq100135ms32860kbC++114.8kb2024-11-11 21:04:282024-11-11 23:05:05

answer

// 私は猫です

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();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{x*=f;return*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;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();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{x*=f;return*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;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();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{x*=f;return*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;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char 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;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
const int mod=998244353,maxn=500005;
vector<int>g[maxn],e[maxn];
bool vis[maxn];
int q[maxn],qL=250000,qR=qL-1,n,d[maxn];
void Solve(){
	cin>>n;
	F(i,0,n-1)g[i].push_back(10*i%n),e[i].push_back((10*i+1)%n);
	memset(d,0x3f,sizeof d),q[++qR]=1,d[1]=1;
	while(qL<=qR){
		int u=q[qL++];
		F(i,0,SZ(g[u])-1){
			const int v=g[u][i];
			if(d[v]>d[u])d[v]=d[u],q[--qL]=v;
		}
		F(i,0,SZ(e[u])-1){
			const int v=e[u][i];
			if(d[v]>d[u]+1)d[v]=d[u]+1,q[++qR]=v;
		}
	}
	cout<<d[0];
}
signed main(){
	const int zsy=1;
	F(_,1,zsy)Solve();
}
// g++ digit.cpp -o a -std=c++14 -O2

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 11ms
memory: 31708kb

input:

81920

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 13ms
memory: 30164kb

input:

55966

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 24ms
memory: 32584kb

input:

92661

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 10
Accepted
time: 12ms
memory: 31040kb

input:

68013

output:

18

result:

ok 1 number(s): "18"

Test #5:

score: 10
Accepted
time: 20ms
memory: 31372kb

input:

72927

output:

27

result:

ok 1 number(s): "27"

Test #6:

score: 10
Accepted
time: 8ms
memory: 27536kb

input:

15047

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 10
Accepted
time: 7ms
memory: 30424kb

input:

59994

output:

36

result:

ok 1 number(s): "36"

Test #8:

score: 10
Accepted
time: 24ms
memory: 32860kb

input:

97273

output:

10

result:

ok 1 number(s): "10"

Test #9:

score: 10
Accepted
time: 8ms
memory: 29884kb

input:

51139

output:

14

result:

ok 1 number(s): "14"

Test #10:

score: 10
Accepted
time: 8ms
memory: 30148kb

input:

55788

output:

15

result:

ok 1 number(s): "15"

Extra Test:

score: 0
Extra Test Passed