QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359155#7686. The Phantom MenaceCodeChildCompile Error//C++175.5kb2024-03-20 13:57:102024-03-20 13:57:11

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 13:57:11]
  • 评测
  • [2024-03-20 13:57:10]
  • 提交

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   ;
#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]; 


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]);  
	
	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 ) ;
 		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 ) ;
 			}
 		} ;
		dfs( dfs , 1 ) ;
		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 ;
	}
	cout << -1 <<'\n'; return ;
} 	
 
 
 
int main(){ 	
 
	ios::sync_with_stdio(false);
	cin.tie( 0 ) ;
	int T ; cin >> T ;
	while(T-- ){	
		solve() ;  
   	}        
 	return  0 ;
}

Details

answer.code:92:31: error: variable ‘std::array<int, 2> StringHash<2>::mod’ has initializer but incomplete type
   92 | array<int, 2> StringHash<HN>::mod =
      |                               ^~~
answer.code:96:31: error: variable ‘std::array<int, 2> StringHash<2>::base’ has initializer but incomplete type
   96 | array<int, 2> StringHash<HN>::base {13331, 998244353};
      |                               ^~~~
answer.code: In lambda function:
answer.code:125:45: error: invalid use of incomplete type ‘struct std::array<int, 2>’
  125 |                         auto l = hs[i].query( 0 , x- 1) , r = hs[i].query( x , m  -1 ) ;
      |                                  ~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/13/bits/memory_resource.h:47,
                 from /usr/include/c++/13/string:58,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from answer.code:9:
/usr/include/c++/13/tuple:2005:45: note: declaration of ‘struct std::array<int, 2>’
 2005 |   template<typename _Tp, size_t _Nm> struct array;
      |                                             ^~~~~
answer.code:127:35: error: ‘r’ was not declared in this scope
  127 |                         if(  !srd[r])   srd[r] = ++tot ;
      |                                   ^
answer.code:128:47: error: ‘r’ was not declared in this scope
  128 |                         edge.push_back( { srd[r] , sld[l] , i }) ;
      |                                               ^
answer.code:128:39: error: no matching function for call to ‘std::vector<std::array<int, 3> >::push_back(<brace-enclosed initializer list>)’
  128 |                         edge.push_back( { srd[r] , sld[l] , i }) ;
      |                         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/queue:63,
                 from answer.code:11:
/usr/include/c++/13/bits/stl_vector.h:1278:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 3>; _Alloc = std::allocator<std::array<int, 3> >; value_type = std::array<int, 3>]’
 1278 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1278:35: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::vector<std::array<int, 3> >::value_type&’ {aka ‘const std::array<int, 3>&’}
 1278 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1295:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::array<int, 3>; _Alloc = std::allocator<std::array<int, 3> >; value_type = std::array<int, 3>]’
 1295 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1295:30: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::vector<std::array<int, 3> >::value_type&&’ {aka ‘std::array<int, 3>&&’}
 1295 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
answer.code:131:45: error: invalid use of incomplete type ‘struct std::array<int, 2>’
  131 |                         auto l = ht[i].query( 0 , m - 1 -  x ) , r = ht[i].query(  m - x  ,  m-1 ) ;
      |                                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/13/tuple:2005:45: note: declaration of ‘struct std::array<int, 2>’
 2005 |   template<typename _Tp, size_t _Nm> struct array;
      |                                             ^~~~~
answer.code:133:35: error: ‘r’ was not declared in this scope
  133 |                         if(  !trd[r])   trd[r] = ++tot ;
      |                                   ^
answer.code:134:47: error: ‘r’ was not declared in this scope
  134 |                         edge.push_back( { trd[r] , tld[l] , i + n }) ;
      |                                               ^
answer.code:134:39: error: no matching function for call to ‘std::vector<std::array<int, 3> >::push_back(<brace-enclosed initializer list>)’
  134 |                         edge.push_back( { trd[r] , tld[l] , i + n }) ;
      |                         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1278:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 3>; _Alloc = std::allocator<std::array<int, 3> >; value_type = std::array<int, 3>]’
 1278 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1278:35: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::vector<std::array<int, 3> >::value_type&’ {aka ‘const std::ar...