QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115377 | #5416. Fabulous Fungus Frenzy | Geothermal# | RE | 3ms | 3676kb | C++17 | 6.4kb | 2023-06-26 05:46:41 | 2023-06-26 05:46:44 |
Judging History
answer
#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 21;
int N, M, K;
vector<vi> goal;
vector<vi> cur;
vector<vector<vi>> pats;
vector<array<int, 3>> ops;
void execute(vector<vi> &pat) {
F0R(i, sz(pat)) {
F0R(j, sz(pat[0])) {
cur[i][j] = 0;
}
}
//dbg(cur);
}
void moveTo(int x, int y, int i, int j) {
while (y > j) {
ops.pb({-2, x+1, y+1});
swap(cur[x][y], cur[x][y-1]);
y--;
}
while (y < j) {
ops.pb({-1, x+1, y+1});
swap(cur[x][y], cur[x][y+1]);
y++;
}
while (x > i) {
ops.pb({-4, x+1, y+1});
swap(cur[x][y], cur[x-1][y]);
x--;
}
while (x < i) {
ops.pb({-3, x+1, y+1});
swap(cur[x][y], cur[x+1][y]);
x++;
}
assert(x == i); assert(y == j);
}
bool makePat(vector<vi> &pat, bool checkFound) {
int cnt[64]; F0R(i, 64) cnt[i] = 0;
F0R(i, N) F0R(j, M) cnt[cur[i][j]]++;
bool found = false;
F0R(i, sz(pat)) F0R(j, sz(pat[0])) {
if (cnt[pat[i][j]]) {
cnt[pat[i][j]]--;
found = true;
} else if (cnt[0]) {
cnt[0]--;
} else return false;
}
if (checkFound && !found) return false;
F0R(i, sz(pat)) {
F0R(j, sz(pat[0])) {
int x = -1, y = -1;
F0R(a, N) {
F0R(b, M) {
if (a*M+b >= i*M+j && cur[a][b] == pat[i][j]) {
x = a; y = b; goto done;
}
}
}
F0R(a, N) {
F0R(b, M) {
if (a*M+b >= i*M+j && cur[a][b] == 0) {
x = a; y = b; goto done;
}
}
}
done:
;
assert(x != -1);
moveTo(x, y, i, j);
}
}
execute(pat);
return true;
}
void solve() {
cin >> N >> M >> K;
goal = vector<vi>(N, vi(M));
cur = vector<vi>(N, vi(M));
int cs[256];
F0R(i, 26) {
cs['a' + i] = 1 + i;
}
F0R(i, 26) {
cs['A' + i] = 27 + i;
}
F0R(i, 10) {
cs['0' + i] = 53 + i;
}
F0R(i, N) {
F0R(j, M) {
char C; cin >> C;
goal[i][j] = cs[(int)C];
}
}
F0R(i, N) {
F0R(j, M) {
char C; cin >> C;
cur[i][j] = cs[(int)C];
}
}
F0R(iter, K) {
int X, Y; cin >> X >> Y;
vector<vi> curPat(X, vi(Y));
F0R(i, X) {
F0R(j, Y) {
char C; cin >> C;
curPat[i][j] = cs[(int)C];
}
}
pats.pb(curPat);
}
bool ok = true;
while (ok) {
ok = false;
F0R(p, sz(pats)) {
if (makePat(pats[p], true)) {
ok = true;
ops.pb({p+1, 1, 1});
pi pos[64]; F0R(i, 64) pos[i] = {-1, -1};
F0R(i, sz(pats[p])) {
F0R(j, sz(pats[p][0])) {
pos[pats[p][i][j]] = {i, j};
}
}
bool found = true;
while (found) {
found = false;
F0R(i, N) {
F0R(j, M) {
if (pos[cur[i][j]].f != -1) {
pi c = pos[cur[i][j]];
found = true;
moveTo(i, j, c.f, c.s);
execute(pats[p]);
ops.pb({p+1, 1, 1});
}
}
}
}
}
}
}
if (!makePat(goal, false)) {
cout << -1 << nl; return;
}
reverse(all(ops));
cout << sz(ops) << nl;
trav(a, ops) {
cout << a[0] << " " << a[1] << " " << a[2] << nl;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while(T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3420kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
17 -4 2 3 -2 1 3 -2 1 2 1 1 1 -2 3 2 -2 3 3 1 1 1 -4 3 1 -2 3 2 1 1 1 -2 2 2 -2 2 3 1 1 1 -2 3 2 -2 2 2 -4 2 1 -4 3 1
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
4 8 4 11122222 33344444 55556666 77777777 NIxSHUOx DExDUIxx DANxSHIx YUANSHEN 2 3 NIy DEx 3 8 zzzzzzzz DANNSH9I YUA9SHEN 1 1 x 2 5 SHO8y DUUI8
output:
213 2 1 1 -4 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -4 4 1 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -4 3 2 -2 3 3 -2 3 4 -2 3 5 -2 3 6 -2 3 7 -2 3 8 1 1 1 -4 2 1 -4 3 1 -4 4 1 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 1 1 1 -4 3 2 -4 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 1 1 1 -4 2 1 -4 3 1...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
8 -4 2 1 1 1 1 -4 2 2 -1 2 1 1 1 1 -4 2 2 -1 2 1 -2 1 2
result:
ok puzzle solved
Test #5:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
2 2 1 OO OO OP PO 2 1 P P
output:
4 -4 2 2 -2 1 2 1 1 1 -2 1 2
result:
ok puzzle solved
Test #6:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
2 2 1 OO OO OP PO 2 2 PP PP
output:
-1
result:
ok puzzle solved
Test #7:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
2 2 1 OO OO OP PP 1 2 OP
output:
7 1 1 1 -4 2 2 -1 2 1 1 1 1 -4 2 2 -1 2 1 1 1 1
result:
ok puzzle solved
Test #8:
score: 0
Accepted
time: 3ms
memory: 3676kb
input:
20 20 20 bofelagiqboebdqplbhq qsrksfthhptcmikjohkt qrnhpoatbekggnkdonet aoalekbmpbisgflbhmol djnhnlitcakltqgegqrt fdctfarsmbnbeosdgilo ttrsljgiratfmioajorh gorljkihdnmnofnblfhm bqjkaehetdjlgctmijpc geslcskpoqjcgtbdspoa riqthroqmmhqgprqhsba fdiarrcomockfqdjjdkd jsbnigfqgsfekbbnnkir ildqctqtqrpcetaocp...
output:
9816 20 1 1 -4 2 1 -4 3 1 -4 4 1 -4 5 1 -4 6 1 -4 7 1 -4 8 1 -4 9 1 -4 10 1 -4 11 1 -4 12 1 -4 13 1 -4 14 1 -4 15 1 -4 16 1 -4 17 1 -4 18 1 -4 19 1 -2 19 2 -2 19 3 -2 19 4 -2 19 5 -2 19 6 -2 19 7 -2 19 8 -2 19 9 -2 19 10 -2 19 11 -2 19 12 -2 19 13 -2 19 14 -2 19 15 -2 19 16 -2 19 17 -2 19 18 -2 19 1...
result:
ok puzzle solved
Test #9:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
20 20 2 HbevPluVL5ORtUFcV9gf Mrq6zdTPMPnwlN7Fpzx6 Nfp71dVuxTZp9Qet0Ca9 ugbaF34DquDdbUnk5x7V fDFszn4PmvMpJ5BDWueJ 2YvFxKJgst8XbftPfy9T F7Q4huk87Lrp1M7i08is Q41E5AqLkkP3Q5qONXC2 MuM7iIzev3ZpxItvriQK 6OBdEC0sso5vdNQlrCSR BJQtKjN6RmppsMGIYL81 yyKsWJSoKorGGblNle0r RkKEQACh8f0bS5nPTtJH fQgoc39vdsPAUmxlYYL...
output:
-1
result:
ok puzzle solved
Test #10:
score: -100
Dangerous Syscalls
input:
20 20 2 pqo3Mcpvo74RFSsJszsa znrYm92Qr8fbqhbCTOgq 4KiMYr0kLAxPGNG15x7L QHKmq6xaJ4PU4msuRAiv UBfS6VUO87hRnMAjGXKX zCgknw3FfhdifmVcT6FF GH6ohIAzZuprlC3vMDVh mHIJ9KlQvWxt6EgGbJkA 3SwJNhRSdEeF9BNtc9k2 mZmEuriH7Rc4ccMjqI0Y cFfI8TC1iM4PkKziLOiN 15CUjuwudnrums3c3dsl ekL52LiFEpzmU4vaGtuX CfrnQtWb5zAN9oQS2fj...