ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197466 | #3448. 心加心 | smwtcat | 100 | 340ms | 1352kb | C++11 | 2.4kb | 2023-11-12 11:23:31 | 2023-11-12 13:18:49 |
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int inv2 = (Mod+1) / 2;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 111;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(int &a, int b){ (b>a) ? (a=b) : 0; }
inline void chmin(int &a, int b){ (b<a) ? (a=b) : 0; }
int n, p;
int pw10[222];
int dis[5050], done[5050];
int val[5050], len[5050];
int main(){
//freopen("ex_heart5.in", "r", stdin);
//freopen("heart.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> p;
pw10[0] = 1; rep(i, 202) pw10[i+1] = pw10[i] * 10 % p;
memset(dis, 0x3f, sizeof(dis));
rep(i, n){
string s;
cin >> s;
int v = 0, l = (int)s.size();
rep(j, l) v = (v * 10 + s[j] - '0') % p;
val[i] = v, len[i] = l;
dis[v] = min(dis[v], l);
//cout << i << ": " << val[i] << " " << len[i] << "\n";
}
rep(cc, 5005){
int u = -1;
rep(i, p) if(!done[i] && (u < 0 || dis[i] < dis[u])) u = i;
if(u < 0) break;
done[u] = 1;
rep(i, n) chmin(dis[(u * pw10[len[i]] + val[i]) % p], dis[u] + len[i]);
}
rep(k, p){
int id = (p - k) % p;
cout << ((dis[id] >= inf) ? -1 : dis[id]) << "\n";
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
10 98 0 1 2 3 4 5 6 7 8 9
output:
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 98 numbers
Test #2:
score: 10
Accepted
time: 14ms
memory: 1328kb
input:
5000 99 14781892056687055378359451878122218601921996058131918743098670380384485452067769009096639454...
output:
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 99 numbers
Test #3:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
3 99 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5...
output:
1 4 7 7 4 4 5 5 8 4 4 4 8 8 4 4 8 9 8 4 8 8 8 8 8 8 8 9 7 7 7 7 7 6 5 5 5 5 6 3 3 3 7 6 2 2 5 5 6 2 ...
result:
ok 99 numbers
Test #4:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
6 95 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9...
output:
1 3 2 2 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 2 2 3 2 2 3 2 2 3 3 2 2 3 2 2 3 2 3 3 3 3 ...
result:
ok 95 numbers
Test #5:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
5 3 412 986 7687 79583 8318
output:
6 3 3
result:
ok 3 number(s): "6 3 3"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1296kb
input:
5 3 5387 39817 6 6804 1
output:
1 2 1
result:
ok 3 number(s): "1 2 1"
Test #7:
score: 10
Accepted
time: 13ms
memory: 1328kb
input:
5000 100 4662215847345417996058539422385909140989122582319939315897492645456767910985172332639303829...
output:
180 180 180 180 180 180 180 180 180 180 180 181 180 180 180 181 180 180 180 181 181 180 180 181 180 ...
result:
ok 100 numbers
Test #8:
score: 10
Accepted
time: 9ms
memory: 1328kb
input:
5000 100 6017404839398900982117908052227697611177103082938397805192623914538500903540418343249962031...
output:
180 180 180 181 182 180 180 181 180 181 180 180 180 180 180 180 180 180 180 180 180 181 180 180 180 ...
result:
ok 100 numbers
Test #9:
score: 10
Accepted
time: 157ms
memory: 1348kb
input:
5000 5000 173577890992330520159895384217403731027027923558584792233344058149389687419038746812531024...
output:
196 184 183 192 192 195 -1 181 194 199 180 -1 180 -1 -1 -1 190 194 -1 185 182 -1 -1 -1 188 184 -1 19...
result:
ok 5000 numbers
Test #10:
score: 10
Accepted
time: 147ms
memory: 1352kb
input:
5000 5000 109684703722761599523811752824414002980896386859466348397242225190298237477285061568577404...
output:
184 180 191 185 195 195 -1 182 181 183 199 -1 192 -1 -1 -1 181 182 -1 185 -1 188 189 190 -1 190 188 ...
result:
ok 5000 numbers
Extra Test:
score: 0
Extra Test Passed