QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245993 | #5473. Move One Coin | Fireball0424# | WA | 2ms | 3936kb | C++14 | 4.5kb | 2023-11-10 15:10:16 | 2023-11-10 15:10:16 |
Judging History
answer
#pragma GCC optimizer("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define ull unsigned long long
#define fr first
#define fi first
#define sc second
#define se second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
using namespace std;
#ifndef fireball
#define tofu ios::sync_with_stdio(0); cin.tie(0);
#else
#define tofu freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}
signed main(){
tofu;
int n1, m1;
cin >> n1 >> m1;
string s[n1];
vector<pii> v1, v2;
for(int i = 0; i < n1; ++i){
cin >> s[i];
for(int j = 0; j < m1; ++j){
if(s[i][j] == 'o') v1.push_back({i, j});
}
}
int n2, m2;
cin >> n2 >> m2;
string t[n2];
for(int i = 0; i < n2; ++i){
cin >> t[i];
for(int j = 0; j < m2; ++j){
if(t[i][j] == 'o') v2.push_back({i, j});
}
}
int sz = (int)v1.size();
auto rotate = [&](){
for(int i = 0; i < sz; ++i){
swap(v1[i].fr, v1[i].sc);
v1[i].sc *= -1;
}
return;
};
sort(all(v1)); sort(all(v2));
for(int rot = 0; rot < 4; ++rot){
// db("v1");
// for(pii i : v1) db(i.fr, i.sc);
// db("v2");
// for(pii i : v2) db(i.fr, i.sc);
// db();
// 1 to 1
int dx = v2[0].fr - v1[0].fr, dy = v2[0].sc - v1[0].sc, fg = 0, fg2 = 0;
for(int i = 1, j = 1; i < sz and j < sz; ++i, ++j){
if(v1[i].fr + dx == v2[j].fr and v1[i].sc + dy == v2[j].sc) continue;
if(fg > 0 and fg2 > 0){
fg2 = -1;
break;
}
else if(fg > 0){
fg2 = j;
i--;
}
else if(fg2 > 0){
fg = i;
j--;
}
else{
if(v1[i].fr + dx == v2[j + 1].fr and v1[i].sc + dy == v2[j + 1].sc){
fg2 = j;
i--;
}
else if(v1[i + 1].fr + dx == v2[j].fr and v1[i + 1].sc + dy == v2[j].sc){
fg = i;
j--;
}
else{
fg2 = -1;
break;
}
}
}
if(fg2 == 0) fg2 = sz - 1;
if(fg2 > 0){
v2[fg2].fr -= dx, v2[fg2].sc -= dy;
for(int tmp = 0; tmp < 4 - rot; ++tmp){
rotate();
swap(v2[fg2].fr, v2[fg2].sc);
v2[fg2].sc *= -1;
}
db(v1[fg].sc, v1[fg].fr);
db(v2[fg2].sc, v2[fg2].fr);
return 0;
}
// 2 to 1
dx = v2[0].fr - v1[1].fr, dy = v2[0].sc - v1[1].sc, fg = 0;
for(int i = 2, j = 1; i < sz and j < sz; ++i, ++j){
if(v1[i].fr + dx == v2[j].fr and v1[i].sc + dy == v2[j].sc) continue;
if(fg){
fg = -1;
break;
}
else{
fg = j;
i--;
}
}
if(fg > 0){
v2[fg].fr -= dx; v2[fg].sc -= dy;
for(int tmp = 0; tmp < 4 - rot; ++tmp){
rotate();
swap(v2[fg].fr, v2[fg].sc);
v2[fg].sc *= -1;
}
db(v1[0].sc, v1[0].fr);
db(v2[fg].sc, v2[fg].fr);
return 0;
}
// 1 to 2
dx = v2[1].fr - v1[0].fr, dy = v2[1].sc - v1[0].sc, fg = 0;
for(int i = 1, j = 2; i < sz and j < sz; ++i, ++j){
if(v1[i].fr + dx == v2[j].fr and v1[i].sc + dy == v2[j].sc) continue;
if(fg){
fg = -1;
break;
}
else{
fg = i;
--j;
}
}
if(fg == 0) fg = sz - 1;
if(fg > 0){
v2[0].fr -= dx; v2[0].sc -= dy;
for(int tmp = 0; tmp < 4 - rot; ++tmp){
rotate();
swap(v2[0].fr, v2[0].sc);
v2[0].sc *= -1;
}
db(v1[fg].sc, v1[fg].fr);
db(v2[0].sc, v2[0].fr);
return 0;
}
rotate();
sort(all(v1));
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3456kb
input:
2 3 xox ooo 4 2 ox ox ox ox
output:
1 0 3 1
result:
ok OK! rot=1
Test #2:
score: 0
Accepted
time: 1ms
memory: 3428kb
input:
3 3 xox oxo xox 4 4 oxxx xxox xoxo xxxx
output:
1 2 -1 -1
result:
ok OK! rot=0
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3936kb
input:
500 500 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
result:
wrong output format Unexpected end of file - int32 expected