#include<bits/stdc++.h>
using namespace std;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
vector<char> find(vector<char> v){
vector<char> k(4,' ');
k[3-1] = v[1]; k[4-1] = v[2];
k[0] = v[3]; k[2-1] = v[4];
if(k[0] == v[2] && k[2] == v[4] && k[1] == v[1] && k[3] == v[3]) return k;
return {};
}
int solve1(int n, vector<vector<char>> v1){
map<pair<char,char>,int> m12,m13,m34,m24;
map<vector<char>,int> m1234,m123, m124, m134, m234;
int ans = 0;
for(int i = 0; i<n; i++){
// 100% CHECKED
vector<char> v = v1[i];
if(m34.find({v[1],v[2]}) != m34.end()){
ans+= m34[{v[1],v[2]}];
}
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
if(m12.find({v[3],v[4]}) != m12.end()){
ans+= m12[{v[3],v[4]}];
}
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
if(m13.find({v[2],v[4]}) != m13.end()){
ans+= m13[{v[2],v[4]}];
}
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
if(m24.find({v[1],v[3]}) != m24.end()){
ans+= m24[{v[1],v[3]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[2]<<v[3]<<" "<<m234[{v[1],v[2],v[3]}]<<endl;
if(v[2] == v[3] && m234.find({v[2],v[4]}) != m234.end()){
ans-=m234[{v[2],v[4]}];
}
if(v[2] == v[3]) m234[{v[1],v[3]}]++;
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
ans+= m1234[find(v)];
// cerr<<"ANS: "<<ans<<" "<<v[2]<<v[3]<<v[4]<<" "<<m123[{v[2],v[3],v[4]}]<<endl;
if(v[2] == v[3] && m123.find({v[1],v[2]}) != m123.end()){
ans-=m123[{v[1],v[2]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[3]<<v[4]<<" "<<m124[{v[1],v[3],v[4]}]<<endl;
if(v[1] == v[4] && m124.find({v[1],v[2]}) != m124.end()){
ans-=m124[{v[1],v[2]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[2]<<v[4]<<" "<<m134[{v[1],v[2],v[4]}]<<endl;
if(v[1] == v[4] && m134.find({v[1],v[3]}) != m134.end()){
ans-=m134[{v[1],v[3]}];
}
vector<char> v1 = {v[2],v[1],v[4],v[3]};
if(!(v[1] == v[2] && v[3] == v[4]) && m1234.find(v1) != m1234.end()){
ans-=m1234[{v[2],v[1],v[4],v[3]}];
}
// if((v[1] == v[2] || v[3] == v[4]) && !(v[1] == v[2] && v[3] == v[4])&& m1234.find(v1) != m1234.end()){
// // 3!
// ans+=m1234[v1];
// }
v1 = {v[3],v[4],v[1],v[2]}; // TAKE CARE OF 2 AND 3
if(!(v[1] == v[3] && v[2] == v[4]) && m1234.find(v1) != m1234.end()){
ans-=m1234[v1];
}
// if((v[1] == v[3] || v[2] == v[4]) && !(v[4] == v[2] && v[3] == v[1])&& m1234.find(v1) != m1234.end()){
// // 3!
// ans+=m1234[v1];
// }
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
m12[{v[1],v[2]}]++;
m13[{v[1],v[3]}]++;
m34[{v[3],v[4]}]++;
m24[{v[2],v[4]}]++;
m1234[{v[1],v[2],v[3],v[4]}]++;
if(v[4] == v [1]) m134[{v[2],v[4]}]++;
if(v[1] == v[4]) m124[{v[3],v[4]}]++;
if(v[2] == v[3]) m123[{v[2],v[4]}]++;
}
return ans;
}
bool check(vector<char> a, vector<char> b){
if(a[1] == b[3] && a[2] == b[4]) return true;
if(a[1] == b[2] && a[3] == b[4]) return true;
if(a[2] == b[1] && a[4] == b[3]) return true;
if(a[3] == b[1] && a[4] == b[2]) return true;
return false;
}
int solve(int n, vector<vector<char>> v){
int ans = 0;
for(int i = 0; i<n; i++){
for(int j = i+1; j<n; j++){
if(check(v[i],v[j])) ans++;
}
}
return ans;
}
int main(){
while(1){
int n = rng()%5;
// cout<<n<<endl;
vector<vector<char>> v;
for(int i = 0; i<n; i++){
int car = rng()%26;
vector<char> v1 = {' '};
for(int j = 0;j < 4; j++){
char c = rng()%26 + 'A';
v1.push_back(c);
// if(j == 1) cout<<endl;
}
// cout<<endl;
v.push_back(v1);
}
if(solve(n,v) != solve1(n,v)){
cout<<n<<endl;
for(int i = 0; i<n; i++){
for(int j = 0; j<4; j++){
cout<<v[i][j+1];
if(j == 1) cout<<endl;
}
cout<<endl;
}
break;
}
}
}
Compilation message
korteles.cpp: In function 'int main()':
korteles.cpp:129:8: warning: unused variable 'car' [-Wunused-variable]
129 | int car = rng()%26;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
532 ms |
412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1028 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1028 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |