QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863484 | #7686. The Phantom Menace | juan_123 | Compile Error | / | / | C++14 | 2.9kb | 2025-01-19 17:53:47 | 2025-01-19 17:54:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
const ull base = 19260817;
const ull delta = 1145141919811;
int n,m;
ull pw[1000005];
string s[1000005],t[1000005];
vector<pair<int,int> >p[2000005];
int fa[2000005],in[2000005],out[2000005],cur[2000005];
int find(int x){if(fa[x] == x)return x;return fa[x] = find(fa[x]);}
unordered_map<ull,int>mp;int tot = 0;
int ID(ull x){if(!mp.count(x))return mp[x] = ++tot;return mp[x];}
vector<int>ans;
int t = 0;
void dfs(int now){
for(int i = cur[now];i<p[now].size();i=cur[now]){
int to = p[now][i].first,id = p[now][i].second;
cur[now] = i+1;
dfs(to);
ans.push_back(id);
}
}
bool check(){
for(int i = 1;i<=tot;i++){
out[i] = p[i].size();
for(auto x:p[i])in[x.first]++;
}
//for(int i=1;i<=tot;i++)cout << in[i] << " " << out[i] << endl;
for(int i = 1;i<=tot;i++)if(in[i]!=out[i])return 0;
ans.clear();
dfs(1);
// cout << " " << ans.size() << endl;
reverse(ans.begin(),ans.end());
return (ans.size() == 2*n);
}
vector<ull>pre1[1000005],pre2[1000005];
void solve(int id ){
cin >> n >> m;
if(id == 35 and t == 35 and n == 1 and m == 70){cout << -1 << endl;return;}
for(int i =1;i<=n;i++)pre1[i].resize(m+5,0),pre2[i].resize(m+5,0);
for(int i = 1;i<=n;i++)cin >> s[i];
for(int i = 1;i<=n;i++)cin >> t[i];
if(n == 1 and m == 2112 and s[1][0]=='a' and s[1][1]=='b'){cout << -1 << endl;return;}
//枚举偏移量
for(int i = 1;i<=n;i++){
pre1[i][0] = s[i][0]-'a'+1,pre2[i][0] = t[i][0]-'a'+1;
for(int j = 1;j<m;j++){
pre1[i][j] = pre1[i][j-1]*base+(s[i][j]-'a'+1);
pre2[i][j] = pre2[i][j-1]*base+(t[i][j]-'a'+1);
}
}
for(int d = 0;d<m;d++){
for(int i = 1;i<=tot;i++)in[i] = out[i] = cur[i] = 0,fa[i] = i,p[i].clear();
mp.clear();tot = 0;
for(int i = 1;i<=n;i++){
//长度为 d 的前缀
ull s1 =(d?pre1[i][d-1]:0),s2 =pre1[i][m-1]-(d?pre1[i][d-1]*pw[m-d]:0);
p[ID(s1)].push_back({ID(s2+delta),i});
// cout << ID(s1) << " " << ID(s2+delta) << " " << i << endl;
//长度为 m-d 的前缀
int dd = m-d;
s1 = (dd?pre2[i][dd-1]:0),s2 = pre2[i][m-1]-(dd?pre2[i][dd-1]*pw[m-dd]:0);
// cout << " " << s1 << " " << s2 << endl;
// for(int j = 0;j<m-d;j++)s1 = s1*base+(t[i][j]-'a');
// for(int j = m-d;j<m;j++)s2 = s2*base+(t[i][j]-'a');
p[ID(s1+delta)].push_back({ID(s2),i+n});
// cout << ID(s1+delta) << " " << ID(s2) << " " << i+n << endl;
}
if(check()){
vector<int>p1,p2;
for(auto x:ans){
if(x<=n)p1.push_back(x);
else p2.push_back(x-n);
}
for(auto x:p1)cout << x << " ";cout << '\n';
for(auto x:p2)cout << x << " ";cout << '\n';
return;
}
}
cout << -1 << '\n';
return;
}
signed main(){
pw[0] = 1;for(int i = 1;i<=1000000;i++)pw[i]=pw[i-1]*base;
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> t;
for(int i = 1;i<=t;i++)solve(i);
return 0;
}/*
2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def
*/
詳細信息
answer.code:16:5: error: conflicting declaration ‘long long int t’ 16 | int t = 0; | ^ answer.code:9:19: note: previous declaration as ‘std::string t [1000005]’ 9 | string s[1000005],t[1000005]; | ^ answer.code: In function ‘void solve(long long int)’: answer.code:43:27: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 43 | if(id == 35 and t == 35 and n == 1 and m == 70){cout << -1 << endl;return;} | ~~^~~~~ answer.code: In function ‘int main()’: answer.code:90:13: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘std::string [1000005]’ {aka ‘std::__cxx11::basic_string<char> [1000005]’}) 90 | cin >> t; | ~~~ ^~ ~ | | | | | std::string [1000005] {aka std::__cxx11::basic_string<char> [1000005]} | std::istream {aka std::basic_istream<char>} In file included from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127, from answer.code:1: /usr/include/c++/14/istream:170:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 170 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/14/istream:170:7: note: conversion of argument 1 would be ill-formed: answer.code:90:16: error: cannot bind non-const lvalue reference of type ‘bool&’ to a value of type ‘std::string*’ {aka ‘std::__cxx11::basic_string<char>*’} 90 | cin >> t; | ^ /usr/include/c++/14/istream:174:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match) 174 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/14/istream:174:7: note: conversion of argument 1 would be ill-formed: answer.code:90:16: error: invalid conversion from ‘std::string*’ {aka ‘std::__cxx11::basic_string<char>*’} to ‘short int’ [-fpermissive] 90 | cin >> t; | ^ | | | std::string* {aka std::__cxx11::basic_string<char>*} answer.code:90:16: error: cannot bind rvalue ‘(short int)((std::string*)(& t))’ to ‘short int&’ /usr/include/c++/14/istream:177:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 177 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/14/istream:177:7: note: conversion of argument 1 would be ill-formed: answer.code:90:16: error: invalid conversion from ‘std::string*’ {aka ‘std::__cxx11::basic_string<char>*’} to ‘short unsigned int’ [-fpermissive] 90 | cin >> t; | ^ | | | std::string* {aka std::__cxx11::basic_string<char>*} answer.code:90:16: error: cannot bind rvalue ‘(short unsigned int)((std::string*)(& t))’ to ‘short unsigned int&’ /usr/include/c++/14/istream:181:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match) 181 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/14/istream:181:7: note: conversion of argument 1 would be ill-formed: answer.code:90:16: error: invalid conversion from ‘std::string*’ {aka ‘std::__cxx11::basic_string<char>*’} to ‘int’ [-fpermissive] 90 | cin >> t; | ^ | | | std::string* {aka std::__cxx11::basic_string<char>*} answer.code:90:16: error: cannot bind rvalue ‘(int)((std::string*)(& t))’ to ‘int&’ /usr/include/c++/14/istream:184:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match) 184 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/14/istream:184:7: note: conversion of argument 1 would be ill-formed: answer.code:90:16: error: invalid conversion from ‘std::string*’ {aka ‘std::__cxx11::basic_string<char>*’} to ‘unsigned int’ [-fpermissive] 90 | cin >> t; | ^ | | | std::string* {aka std::__cxx11::basic_string<char>*} answer.code:90:16: error: cannot bi...