QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291118 | #2855. Phone Numbers | MoRanSky | 100 ✓ | 726ms | 6588kb | C++23 | 6.9kb | 2023-12-26 04:55:48 | 2023-12-26 04:55:49 |
Judging History
answer
// 抄袭的 xtqqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T> bool chkmax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkmin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int P = 1e9 + 7, N = 4e3 + 5, M = 1e5 + 5;
int n, ncnt;
int trans[N][10][10];
LL d[N], f[N];
char s[M];
bool can[N];
map<pair<vi, vi>, int> dfn;
pair<vi, vi> rnk[N];
pii pl[10] = {mp(0, 0), mp(1, 1), mp(1, 2), mp(1, 3), mp(2, 1), mp(2, 2), mp(2, 3), mp(3, 1), mp(3, 2), mp(3, 3)};
bool check4(int a1, int a2, int a3, int a4, int b1, int b2, int b3, int b4) {
if (a1 == a2 || a1 == a3 || a1 == a4 || a2 == a3 || a2 == a4 || a3 == a4) return false;
if (b1 == b2 || b1 == b3 || b1 == b4 || b2 == b3 || b2 == b4 || b3 == b4) return false;
vi t = {a1, a2, a3, a4, b1, b2, b3, b4};
int mina[2] = {3, 3}, maxa[2] = {1, 1};
for (auto r : t) {
chkmin(mina[0], pl[r].fi), chkmax(maxa[0], pl[r].fi);
chkmin(mina[1], pl[r].se), chkmax(maxa[1], pl[r].se);
}
return maxa[0] - mina[0] <= 1 && maxa[1] - mina[1] <= 1;
}
bool check2(int a1, int a2, int b1, int b2) {
if (a1 == a2 || b1 == b2) return false;
vi t = {a1, a2, b1, b2};
int mina[2] = {3, 3}, maxa[2] = {1, 1};
for (auto r : t) {
chkmin(mina[0], pl[r].fi), chkmax(maxa[0], pl[r].fi);
chkmin(mina[1], pl[r].se), chkmax(maxa[1], pl[r].se);
}
return maxa[0] - mina[0] + maxa[1] - mina[1] == 1;
}
void dfs(pair<vi, vi> u) {
dfn[u] = ++ncnt;
rnk[ncnt] = u;
int lab = ncnt;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (abs(pl[i].fi - pl[j].fi) > 1 || abs(pl[i].se - pl[j].se) > 1) continue;
auto now = u;
now.fi.pb(i), now.se.pb(j);
if (now.fi.size() == 6) {
if (!check4(now.fi[3], now.fi[4], i, j, now.se[3], now.se[4], j, i) && !check4(now.fi[2], now.fi[3], now.fi[4], i, now.se[2], now.se[3], now.se[4], j)) {
if (abs(pl[now.fi[2]].fi - pl[now.fi[3]].fi) == 1 && abs(pl[now.fi[2]].se - pl[now.fi[3]].se) == 1) {
now.fi = vi{now.fi[4], now.fi[5]};
now.se = vi{now.se[4], now.se[5]};
} else {
now.fi = vi{now.fi[5]};
now.se = vi{now.se[5]};
}
} else {
now.fi.erase(now.fi.begin()), now.se.erase(now.se.begin());
now.fi[1] = now.se[1] = 0;
}
} else if (now.fi.size() == 5) {
if (i == j) now.fi = vi{i}, now.se = vi{j};
else if (!check4(now.fi[2], now.fi[3], i, j, now.se[2], now.se[3], j, i)) now.fi = vi{i}, now.se = vi{j};
else now.fi[0] = now.fi[1] = now.se[0] = now.se[1] = 0;
}
if (now.fi.size() == 4) {
if (!check4(now.fi[0], now.fi[1], now.fi[2], now.fi[3], now.se[0], now.se[1], now.se[2], now.se[3])) {
if (now.fi[0] != now.se[0]) continue;
else now.fi.erase(now.fi.begin()), now.se.erase(now.se.begin());
} else if (now.fi[0] != now.se[0] || now.fi[1] != now.se[1]) now.fi.clear(), now.se.clear();
}
if (now.fi.size() == 3) {
if (now.fi[0] == now.se[0]) {
bool fl = 0;
for (int k = 1; k <= 9; k++)
for (int l = 1; l <= 9; l++)
if (check4(now.fi[0], now.fi[1], now.fi[2], k, now.se[0], now.se[1], now.se[2], l)
&& !check2(now.fi[1], now.fi[2], now.se[1], now.se[2])
&& !check2(now.fi[2], k, now.se[2], l) && (now.fi[1] != now.se[1] || now.fi[2] != now.se[2]))
fl = 1;
if (!fl) now.fi.erase(now.fi.begin()), now.se.erase(now.se.begin());
} else {
bool fl = 0;
for (int k = 1; k <= 9; k++)
for (int l = 1; l <= 9; l++)
if (check4(now.fi[0], now.fi[1], now.fi[2], k, now.se[0], now.se[1], now.se[2], l))
fl = 1;
if (!fl) continue;
}
}
if (now.fi.size() == 2) {
if (now.fi[0] != now.se[0] && check2(now.fi[0], now.fi[1], now.se[0], now.se[1])) now.fi.clear(), now.se.clear();
else if (now.fi[0] == now.se[0]) {
if (now.fi[0] == now.fi[1] || now.se[0] == now.se[1]) now.fi.erase(now.fi.begin()), now.se.erase(now.se.begin());
if (abs(pl[now.fi[1]].fi - pl[now.fi[0]].fi) > 1 || abs(pl[now.fi[1]].se - pl[now.fi[0]].se) > 1
|| abs(pl[now.se[1]].fi - pl[now.fi[0]].fi) > 1 || abs(pl[now.se[1]].se - pl[now.fi[0]].se) > 1)
now.fi.erase(now.fi.begin()), now.se.erase(now.se.begin());
} else if (now.fi[0] == now.fi[1] || now.se[0] == now.se[1]) continue;
}
if (!dfn.count(now)) dfs(now);
trans[lab][i][j] = dfn[now];
}
}
}
int main() {
dfs(mp(vi(), vi()));
for (int i = 1; i <= ncnt; i++) {
pair<vi, vi> u = rnk[i];
if (u.fi.size() == 0) can[i] = 1;
else if (u.fi.size() == 1) can[i] = u.fi[0] == u.se[0];
else if (u.fi.size() == 2) can[i] = u.fi[0] == u.se[0] && u.fi[1] == u.se[1];
else if (u.fi.size() == 3) can[i] = (u.fi[0] == u.se[0] && check2(u.fi[1], u.fi[2], u.se[1], u.se[2])) || check2(u.fi[0], u.fi[1], u.se[0], u.se[1]) && u.fi[2] == u.se[2];
else if (u.fi.size() == 4) can[i] = 1;
else if (u.fi.size() == 5) can[i] = abs(pl[u.fi[3]].fi - pl[u.fi[4]].fi) == 1 && abs(pl[u.fi[3]].se - pl[u.fi[4]].se) == 1;
}
int T; read(T);
while (T--) {
scanf("%s", s + 1);
n = strlen(s + 1);
for (int i = 1; i <= ncnt; i++) d[i] = f[i] = 0;
d[1] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= ncnt; j++) {
if (!d[j]) continue;
for (int k = 1; k <= 9; k++) f[trans[j][s[i] - '0'][k]] += d[j];
}
for (int j = 1; j <= ncnt; j++) d[j] = f[j] % P, f[j] = 0;
}
LL ans = 0;
for (int i = 1; i <= ncnt; i++)
if (can[i])
ans = (ans + d[i]) % P;
printf("%lld\n", ans);
}
return 0;
}
详细
Test #1:
score: 4.7619
Accepted
time: 85ms
memory: 6236kb
input:
5 1478 4455 5968 31313211 123659874
output:
5 2 24 3 255
result:
ok 5 lines
Test #2:
score: 4.7619
Accepted
time: 86ms
memory: 6236kb
input:
1 5689152484578625359683652141745263254158478962534251632585963749647856412524517957586984215581247851
output:
972152931
result:
ok single line: '972152931'
Test #3:
score: 4.7619
Accepted
time: 85ms
memory: 6240kb
input:
1 5632457812563254176895625326926357123526235625784965815246985475849652371536295688574785693152469589
output:
938269333
result:
ok single line: '938269333'
Test #4:
score: 4.7619
Accepted
time: 82ms
memory: 6428kb
input:
1 7366565897458963524563258478595681542364652847587698562145851352635236517845214581542458714721865325
output:
201642487
result:
ok single line: '201642487'
Test #5:
score: 4.7619
Accepted
time: 91ms
memory: 6496kb
input:
1 5236958653215326425168596251474687896352653296858596754887774854651422536485695232652638987418236585474563526598215453622921453524154962387213256984574875375484786959865457856598657412548755658745784985745912678124586915421544652352147584578452547851245895623547825412458547154258798754413256458742...
output:
916143108
result:
ok single line: '916143108'
Test #6:
score: 4.7619
Accepted
time: 88ms
memory: 6220kb
input:
1 3256528529895689542515668598475854213256125487325642513265213562568972536784548578426539586635236542164215322856326523641525847632598614564758742157484512857512412514574875632784531245856236254356245986895689478523459865323694756252164578824514424156386958742542165239889253625489563562967862358786...
output:
533086196
result:
ok single line: '533086196'
Test #7:
score: 4.7619
Accepted
time: 83ms
memory: 6240kb
input:
1 2356235623562356235623562356235623562356235623562356235623562356235623562356233154215421542154215421542154215421542154215421542154215421542154215421542154215421542154215421542154652365236585748574857485748574857485748574857485748574857485748574857485748574857485748574857485748574857485748574857485...
output:
184251256
result:
ok single line: '184251256'
Test #8:
score: 4.7619
Accepted
time: 150ms
memory: 6232kb
input:
1 2365662356796882362574578658545879652345148755968687415215478124512885742365865952365981298574521659562398562353263832478547865978453257652367485782653458974521456987987452632512456143254145875623425195865326584785986854768915249263542147856941612536441536289562316542151962536315242514362525835784...
output:
834451116
result:
ok single line: '834451116'
Test #9:
score: 4.7619
Accepted
time: 149ms
memory: 6440kb
input:
1 6985749568596547898968574578358368754578356295685241432651422541263589615249145865325835264512547658998475265379647858474589478475845632874592541298651524695845652547826534875478823657851785454785796586914632578124574652345874736184756356899856412569869568769585961524859584721222658747412356758432...
output:
733198963
result:
ok single line: '733198963'
Test #10:
score: 4.7619
Accepted
time: 150ms
memory: 6244kb
input:
1 8548754875487563526352635263526352635263526352635263526352635263526352635247888457845784578457845784578457845784578457845784578457845784856985698569856985698569856985692159865986598659865986598659865986598659865986598659821498569856985698569856985698569856985698569856985765896589658965896589658965...
output:
114987343
result:
ok single line: '114987343'
Test #11:
score: 4.7619
Accepted
time: 719ms
memory: 6284kb
input:
1 4521369857474581865963251879875478458563524598689658623541256245125236574236589652154216895235869235124754875986588251456983256374585578478685945876523625921587498654487581425964769625655893562472536279685412514896545215638352684572385963478574452634421537584658954567548326589615245865945596958616...
output:
569583013
result:
ok single line: '569583013'
Test #12:
score: 4.7619
Accepted
time: 85ms
memory: 6196kb
input:
10 15823565 45362152 15758472 65245788 87584541 78454439 36527845 32598698 41252659 41684575
output:
52 60 42 72 86 26 576 106 54 48
result:
ok 10 lines
Test #13:
score: 4.7619
Accepted
time: 720ms
memory: 6308kb
input:
1 5784575477823241589251425689523674152584128965912784574581254253653287541287785421523514255986745821171288659586935263475842154124152356285748541257841255487215459869265356954526958632145528751246895781659894598645125419874536274585236895214512471528596548765612454625326487549568553625145787488569...
output:
520298668
result:
ok single line: '520298668'
Test #14:
score: 4.7619
Accepted
time: 726ms
memory: 6328kb
input:
1 6652365236523652365236523626325632563256325632563256325632563256325636917499958695869586958695869586958695869586958695869586958695863256325632563256325632563256325632563256325632563256325632563256325632563256325632563256325632563255412541254125412541254125412541298569856985698569856985698569856985...
output:
940331227
result:
ok single line: '940331227'
Test #15:
score: 4.7619
Accepted
time: 85ms
memory: 6236kb
input:
10 41452444 25364521 47856325 89421535 21547582 47986587 22563698 25966932 14527854 11487596
output:
27 576 633 48 92 100 78 16 576 52
result:
ok 10 lines
Test #16:
score: 4.7619
Accepted
time: 683ms
memory: 6332kb
input:
1 2211333133211122313223132213112231211222221132113311111231323123132311222112322232221122123231313323111313123221322212322213331313212121313323211232332212322313333112312111223212113323311231123131213221313221221113233313233133123323312323221131213132132213133121123213311222211212311313122221211321...
output:
82299876
result:
ok single line: '82299876'
Test #17:
score: 4.7619
Accepted
time: 676ms
memory: 6308kb
input:
1 2321322112321131132132121322323222222122321332313131112312321332333321213233132112213231122123133212312123133332133331222333111323321223121231132313311333223133122333332123331332321232121233322323312233233121223311112221221111212231312131211332113222113223122333122113111331133231232223233213322331...
output:
497823104
result:
ok single line: '497823104'
Test #18:
score: 4.7619
Accepted
time: 696ms
memory: 6328kb
input:
1 9632498212241749941489839189269743221216342632367493649143671626418787483678926947278792496247214983923223896894694699987874416728994778938714239638983693297146337714232682323844896362197912892363869218689211289276783161646912361231238498781692119963281472967832378421323968417227422149398296932121...
output:
109660966
result:
ok single line: '109660966'
Test #19:
score: 4.7619
Accepted
time: 690ms
memory: 6332kb
input:
1 2121273223647696914414786691247434838489899122899463321247246416183936189698824712472132986368798712327868963749932926143278333986912696484723696871217847788932863347411969632984636669861489636696662113468969232899837614163621891439749744783329869129476787847268368764132374139664198796313288212432...
output:
40100194
result:
ok single line: '40100194'
Test #20:
score: 4.7619
Accepted
time: 721ms
memory: 6288kb
input:
1 5598585586569568598658986956996589695869958586959869895685965856958698598658568956869588965695868586958656989596865998656598658968598696858969856956558698655859688969995869958695689556658958965569586896985659685899988569865598659885659866958956899859895685689565885698965986986565988596698589965856...
output:
602457661
result:
ok single line: '602457661'
Test #21:
score: 4.7619
Accepted
time: 725ms
memory: 6588kb
input:
1 5698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856985698569856...
output:
759378925
result:
ok single line: '759378925'