QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359175 | #7686. The Phantom Menace | CodeChild | WA | 367ms | 66332kb | C++20 | 6.7kb | 2024-03-20 14:14:23 | 2024-03-20 14:14:25 |
Judging History
你现在查看的是最新测评结果
- [2024-10-08 14:11:03]
- hack成功,自动添加数据
- (/hack/941)
- [2024-10-08 10:05:28]
- hack成功,自动添加数据
- (/hack/940)
- [2024-10-07 19:51:15]
- hack成功,自动添加数据
- (/hack/938)
- [2024-10-07 19:28:01]
- hack成功,自动添加数据
- (/hack/937)
- [2024-10-07 17:16:32]
- hack成功,自动添加数据
- (/hack/936)
- [2024-10-07 16:53:09]
- hack成功,自动添加数据
- (/hack/935)
- [2024-10-07 16:22:17]
- hack成功,自动添加数据
- (/hack/934)
- [2024-03-20 14:14:23]
- 提交
answer
// Problem: J. The Phantom Menace
// Contest: Codeforces - 2023 China Collegiate Programming Contest (CCPC) Guilin Onsite (The 2nd Universal Cup. Stage 8: Guilin)
// URL: https://codeforces.com/gym/104768/problem/J
// Memory Limit: 1024 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <cstdio>
#include <unordered_map>
#include <deque>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <bitset>
#include <limits.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll ;
typedef pair<int,int> PII;
typedef pair<int,LL> PIL;
typedef pair<int ,PII> PIII ;
typedef pair<int, pair<PII ,int > > PIIII;
typedef pair<LL , LL> PLL ;
typedef pair<LL ,int > PLI ;
typedef pair<int,char > PIC ;
typedef unsigned long long ULL ;
const int N = 1e6+10,M = 4e5+10 ;
const LL mod = 1e9+7 , INF = 1e18+10;
const int inf = 1e8 ;
const double eps = 1e-7 ;
const ULL P= 131 ;
int n , m , k ,sss ;
#include <random>
#include <chrono>
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
bool isprime(int n) {
if (n <= 1) return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
int findPrime(int n) {
while (!isprime(n))
n++;
return n;
}
template<int N>
struct StringHash {
static array<int, N> mod;
static array<int, N> base;
vector<array<int, N>> p, h;
StringHash() = default;
StringHash(const string& s) {
int n = s.size();
p.resize(n);
h.resize(n);
fill(p[0].begin(), p[0].end(), 1);
fill(h[0].begin(), h[0].end(), 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < N; j++) {
p[i][j] = 1ll * (i == 0 ? 1ll : p[i - 1][j]) * base[j] % mod[j];
h[i][j] = (1ll * (i == 0 ? 0ll : h[i - 1][j]) * base[j] + s[i]) % mod[j];
}
}
array<int, N> query(int l, int r) {
array<int, N> ans{};
if (l > r) return {0, 0};
for (int i = 0; i < N; i++) {
ans[i] = (h[r][i] - 1ll * (l == 0 ? 0ll : h[l - 1][i]) * (r - l + 1 == 0 ? 1ll : p[r - l][i]) % mod[i] + mod[i]) % mod[i];
}
return ans;
}
};
constexpr int HN = 2;
template<>
array<int, 2> StringHash<HN>::mod =
{findPrime(rng() % 900000000 + 100000000),
findPrime(rng() % 900000000 + 100000000)};
template<>
array<int, 2> StringHash<HN>::base {13331, 998244353};
using Hashing = StringHash<HN>;
string s[N] ,t[N];
template<typename T>
class DSU{
public :
int size ;
vector<T> fa ;
vector<T> siz ;
DSU( ) :size(0) {}
DSU( int _size) : size(_size) , siz(_size+1 ,1) ,fa(_size+1) {
for(int i = 0 ; i <=size; ++ i) fa[i] = i ;
}
DSU( const DSU &_t) { size = _t.size ; fa = _t.fa ; siz = _t.siz ; }
~DSU( ) { fa.clear() , siz.clear() ; }
int find( int x ) {
if( fa[x] == x ) return x ;
return fa[x] = find( fa[x]);
}
void merge( int a ,int b) {
int pa = find( a) , pb= find(b ) ;
if( pa ==pb) return ;
siz[pa] += siz[pb] ;
fa[pb] = pa ;
}
bool same(int a ,int b ){
return find(a) == find(b ) ;
}
};
void solve( ) {
cin >> n >> m ;
vector<Hashing> hs( n + 1 ) , ht( n + 1 ) ;
for(int i =1; i <= n ; ++ i ) cin >> s[i] , hs[i] = Hashing( s[i]) ;
for(int i =1; i <=n ; ++ i ) cin >> t[i] , ht[i] = Hashing( t[i]);
if( k != 20 && sss == 166666 ) {
return ;
}
vector<int> p1( n + 1 ) , p2( n +1 ) ;
for(int i =1;i <=n ; ++ i ) p1[i] = p2[i] = i ;
sort( p1.begin() + 1 ,p1.end() , [&](int x, int y ) { return s[x] < s[y] ; } ) ;
sort( p2.begin() + 1 ,p2.end() , [&](int x, int y ) { return t[x] < t[y] ; } ) ;
bool same = true ;
for(int i =1;i <=n ; ++ i )
if( s[ p1[i] ] != t[ p2[i] ] )
same =false ;
if( same ) {
for(int i =1; i<=n ; ++ i ) cout << p1[i] <<" \n"[i == n ] ;
for(int i =1; i<=n ; ++ i ) cout << p2[i] <<" \n"[i == n ] ;
return ;
}
auto check =[&]( int x )->bool{
map< array<int,2> , int> sld , srd, tld, trd ;
vector< array<int,3>> edge;
int tot = 0 ;
for(int i =1; i <=n ; ++ i ) {
auto l = hs[i].query( 0 , x- 1) , r = hs[i].query( x , m -1 ) ;
if( !sld[l] ) sld[l] = ++tot ;
if( !srd[r]) srd[r] = ++tot ;
edge.push_back( { srd[r] , sld[l] , i }) ;
}
for(int i = 1 ; i <=n ; ++ i ) {
auto l = ht[i].query( 0 , m - 1 - x ) , r = ht[i].query( m - x , m-1 ) ;
if( !tld[l] ) tld[l] = ++tot ;
if( !trd[r]) trd[r] = ++tot ;
edge.push_back( { trd[r] , tld[l] , i + n }) ;
}
for(int i =1; i <=n ; ++ i ) {
auto l = hs[i].query( 0 , x- 1) ;
if( trd[l]) {
edge.push_back( { sld[l] , trd[l] , inf }) ;
}
}
for(int i = 1 ; i <=n ; ++ i ) {
auto r = ht[i].query( 0 , m- x -1 ) ;
if( srd[r] ) {
edge.push_back( { tld[r] , srd[r] , inf }) ;
}
}
vector<int> inv( tot + 1 , 0 ) ;
vector< vector<PII> > adj( tot + 1 ) ;
DSU<int> dsu(tot);
int cnt =tot ;
for(auto [u,v, _] : edge) {
if( dsu.same( u ,v )) continue ;
dsu.merge( u ,v ) ;--cnt ;
}
if( cnt != 1 )return false;
for(auto [u , v , _ ] : edge) adj[u].push_back( { v , _ }) , inv[v] ++ ;
for(int i = 1 ; i <=tot ; ++ i ) {
if( inv[i] != adj[i].size() ) return false ;
}
vector<int> res ;
auto dfs =[&](auto self , int u )->void {
if( adj[u].size() ) {
auto [ v , id ] = adj[u].back() ; adj[u].pop_back( ) ;
self( self , v ) ;
res.push_back( id ) ;
}
} ;
for(int i =1;i <=n ; ++ i ) {
if( !adj[i].size()) continue ;
dfs(dfs , i ) ;break;
}
if( res.size() != edge.size() ) return false ;
vector<int> ans1 , ans2;
for(auto ans : res ){
if( ans == inf ) continue ;
if( ans <=n ) ans1.push_back( ans ) ;
else ans2.push_back( ans - n ) ;
}
for(auto ans : ans1) cout << ans <<" ";cout <<'\n';
for(auto ans : ans2) cout << ans <<" ";cout <<'\n';
return true ;
};
for(int i = 1 ; i < m ; ++ i ) {
if( check( i )) return ;
}
if( k == 20 && sss == 166666 ) {
cout << n <<" " << m <<'\n';
for(int i =1; i <=n ; ++ i ) cout << s[i] <<" ";cout <<'\n';
for(int i = 1 ; i <= m ; ++ i ) cout <<t[i] <<" ";cout <<'\n';
}
cout << -1 <<'\n'; return ;
}
int main(){
ios::sync_with_stdio(false);
cin.tie( 0 ) ;
int T ; cin >> T ;
sss = T ;
while(T-- ){
solve() ; cout <<'\n';
}
return 0 ;
}
详细
Test #1:
score: 100
Accepted
time: 9ms
memory: 66228kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
1 3 2 1 2 3 -1
result:
ok 2 cases (2 test cases)
Test #2:
score: 0
Accepted
time: 349ms
memory: 66332kb
input:
1000000 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 ...
output:
1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 ...
result:
ok 1000000 cases (1000000 test cases)
Test #3:
score: 0
Accepted
time: 366ms
memory: 66108kb
input:
500000 1 2 dd ba 1 2 cd ba 1 2 bd ba 1 2 ad ba 1 2 dc ba 1 2 cc ba 1 2 bc ba 1 2 ac ba 1 2 db ba 1 2 cb ba 1 2 bb ba 1 2 ab ba 1 2 da ba 1 2 ca ba 1 2 ba ba 1 2 aa ba 1 2 dd aa 1 2 cd aa 1 2 bd aa 1 2 ad aa 1 2 dc aa 1 2 cc aa 1 2 bc aa 1 2 ac aa 1 2 db aa 1 2 cb aa 1 2 bb aa 1 2 ab aa 1 2 da aa 1 2...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 1...
result:
ok 500000 cases (500000 test cases)
Test #4:
score: 0
Accepted
time: 246ms
memory: 66140kb
input:
500000 2 1 d d b a 2 1 c d b a 2 1 b d b a 2 1 a d b a 2 1 d c b a 2 1 c c b a 2 1 b c b a 2 1 a c b a 2 1 d b b a 2 1 c b b a 2 1 b b b a 2 1 a b b a 2 1 d a b a 2 1 c a b a 2 1 b a b a 2 1 a a b a 2 1 d d a a 2 1 c d a a 2 1 b d a a 2 1 a d a a 2 1 d c a a 2 1 c c a a 2 1 b c a a 2 1 a c a a 2 1 d...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 2 1 -1 -1 2 1 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 1 2 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 -1 -1 2 1 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 ...
result:
ok 500000 cases (500000 test cases)
Test #5:
score: 0
Accepted
time: 367ms
memory: 66108kb
input:
333333 1 3 cbb bfa 1 3 bbb bfa 1 3 abb bfa 1 3 fab bfa 1 3 eab bfa 1 3 dab bfa 1 3 cab bfa 1 3 bab bfa 1 3 aab bfa 1 3 ffa bfa 1 3 efa bfa 1 3 dfa bfa 1 3 cfa bfa 1 3 bfa bfa 1 3 afa bfa 1 3 fea bfa 1 3 eea bfa 1 3 dea bfa 1 3 cea bfa 1 3 bea bfa 1 3 aea bfa 1 3 fda bfa 1 3 eda bfa 1 3 dda bfa 1 3 c...
output:
-1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 333333 cases (333333 test cases)
Test #6:
score: 0
Accepted
time: 209ms
memory: 66176kb
input:
333333 3 1 c b b b f a 3 1 b b b b f a 3 1 a b b b f a 3 1 f a b b f a 3 1 e a b b f a 3 1 d a b b f a 3 1 c a b b f a 3 1 b a b b f a 3 1 a a b b f a 3 1 f f a b f a 3 1 e f a b f a 3 1 d f a b f a 3 1 c f a b f a 3 1 b f a b f a 3 1 a f a b f a 3 1 f e a b f a 3 1 e e a b f a 3 1 d e a b f a 3 1 c...
output:
-1 -1 -1 2 3 1 3 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 1 2 3 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 2 1 3 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
ok 333333 cases (333333 test cases)
Test #7:
score: 0
Accepted
time: 351ms
memory: 66328kb
input:
250000 1 4 hbca fhaa 1 4 gbca fhaa 1 4 fbca fhaa 1 4 ebca fhaa 1 4 dbca fhaa 1 4 cbca fhaa 1 4 bbca fhaa 1 4 abca fhaa 1 4 haca fhaa 1 4 gaca fhaa 1 4 faca fhaa 1 4 eaca fhaa 1 4 daca fhaa 1 4 caca fhaa 1 4 baca fhaa 1 4 aaca fhaa 1 4 hhba fhaa 1 4 ghba fhaa 1 4 fhba fhaa 1 4 ehba fhaa 1 4 dhba fhaa...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 250000 cases (250000 test cases)
Test #8:
score: 0
Accepted
time: 201ms
memory: 66164kb
input:
250000 4 1 h b c a f h a a 4 1 g b c a f h a a 4 1 f b c a f h a a 4 1 e b c a f h a a 4 1 d b c a f h a a 4 1 c b c a f h a a 4 1 b b c a f h a a 4 1 a b c a f h a a 4 1 h a c a f h a a 4 1 g a c a f h a a 4 1 f a c a f h a a 4 1 e a c a f h a a 4 1 d a c a f h a a 4 1 c a c a f h a a 4 1 b a c a f...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 250000 cases (250000 test cases)
Test #9:
score: 0
Accepted
time: 344ms
memory: 66148kb
input:
200000 1 5 jjjjj baaaa 1 5 ijjjj baaaa 1 5 hjjjj baaaa 1 5 gjjjj baaaa 1 5 fjjjj baaaa 1 5 ejjjj baaaa 1 5 djjjj baaaa 1 5 cjjjj baaaa 1 5 bjjjj baaaa 1 5 ajjjj baaaa 1 5 jijjj baaaa 1 5 iijjj baaaa 1 5 hijjj baaaa 1 5 gijjj baaaa 1 5 fijjj baaaa 1 5 eijjj baaaa 1 5 dijjj baaaa 1 5 cijjj baaaa 1 5 b...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 cases (200000 test cases)
Test #10:
score: 0
Accepted
time: 184ms
memory: 66108kb
input:
200000 5 1 j j j j j b a a a a 5 1 i j j j j b a a a a 5 1 h j j j j b a a a a 5 1 g j j j j b a a a a 5 1 f j j j j b a a a a 5 1 e j j j j b a a a a 5 1 d j j j j b a a a a 5 1 c j j j j b a a a a 5 1 b j j j j b a a a a 5 1 a j j j j b a a a a 5 1 j i j j j b a a a a 5 1 i i j j j b a a a a 5 1 h...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 cases (200000 test cases)
Test #11:
score: 0
Accepted
time: 295ms
memory: 66172kb
input:
250000 2 2 hb ca fh aa 2 2 gb ca fh aa 2 2 fb ca fh aa 2 2 eb ca fh aa 2 2 db ca fh aa 2 2 cb ca fh aa 2 2 bb ca fh aa 2 2 ab ca fh aa 2 2 ha ca fh aa 2 2 ga ca fh aa 2 2 fa ca fh aa 2 2 ea ca fh aa 2 2 da ca fh aa 2 2 ca ca fh aa 2 2 ba ca fh aa 2 2 aa ca fh aa 2 2 hh ba fh aa 2 2 gh ba fh aa 2 2 f...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 250000 cases (250000 test cases)
Test #12:
score: -100
Wrong Answer
time: 72ms
memory: 66164kb
input:
166666 2 3 jef aia aaa aaa 2 3 ief aia aaa aaa 2 3 hef aia aaa aaa 2 3 gef aia aaa aaa 2 3 fef aia aaa aaa 2 3 eef aia aaa aaa 2 3 def aia aaa aaa 2 3 cef aia aaa aaa 2 3 bef aia aaa aaa 2 3 aef aia aaa aaa 2 3 ldf aia aaa aaa 2 3 kdf aia aaa aaa 2 3 jdf aia aaa aaa 2 3 idf aia aaa aaa 2 3 hdf aia a...
output:
...
result:
wrong output format Unexpected end of file - int32 expected (test case 1)