QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102317 | #6380. LaLa and Divination Magic | zhaohaikun | RE | 1ms | 15824kb | C++14 | 6.9kb | 2023-05-02 23:37:48 | 2023-05-02 23:37:52 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O1")
#pragma GCC optimize ("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
inline char gc() {
static char ch[100000], *l, *r;
return (l == r && (r = (l = ch) + fread(ch, 1, 100000, stdin), l == r)) ? EOF : *l++;
}
inline void pc(char c) {
static char ch[100000], *r = ch;
if (!c || r - ch == 100000) fwrite(ch, 1, r - ch, stdout), r = ch;
*r++ = c;
}
template <typename T> void read(T &x) {
x = 0; int f = 1; char c = gc();
for (; !isdigit(c); c = gc()) if (c == '-') f = -f;
for (; isdigit(c); c = gc()) x = x * 10 + c - '0';
x *= f;
}
template <typename T> void write(T x) {
T l = 0; ull y = 0;
if (!x) { pc(48); return; }
if (x < 0) { x = -x; pc('-'); }
while (x) { y = y * 10 + x % 10; x /= 10; ++l; }
while (l) { pc(y % 10 + 48); y /= 10; --l; }
}
template <typename T> void writes(T x) { write(x); pc(32); }
template <typename T> void writeln(T x) { write(x); pc('\n'); }
const int N = 2010;
int n, m, nn, cc[4];
bool st[N][N];
bitset <N> s0[N], s1[N], ss0, ss1;
bool t[4][N][N];
vector <pair <int, pair <int, int>>> ans;
vector <int> v[N * 2], v2[N * 2];// tt[N * 2];
int dfn[N * 2], low[N * 2], cnt, sccnum[N * 2], sta[N * 2], tot, scccnt;
void tarjan(int x) {
low[x] = dfn[x] = ++cnt;
sta[tot++] = x;
for (int i: v[x])
if (!dfn[i]) {
tarjan(i);
chkmin(low[x], low[i]);
} else if (!sccnum[i]) {
chkmin(low[x], low[i]);
}
if (low[x] == dfn[x]) {
scccnt++;
while (sta[tot] != x) {
sccnum[sta[--tot]] = scccnt;
}
}
}
bitset <N * 2> ok[N * 2], ook[N * 2];
// vector <int> chk[N * 2], chk2[N * 2];
void solve(int x, bitset <N * 2> y) {
if(((y << m) & y).any()) return;
if (x == m + 1) {
if (++nn > n) {
puts("-1");
exit(0);
}
return;
}
if (!y[x + m]) solve(x + 1, y | ok[sccnum[x]]);
if (!y[x]) solve(x + 1, y | ok[sccnum[x + m]]);
}
signed main() {
cc[0] = 0, cc[1] = 2, cc[2] = 1, cc[3] = 3;
read(n); read(m);
F(i, 1, n) {
F(j, 1, m) {
char ch = gc();
while (!isdigit(ch)) ch = gc();
st[i][j] = (ch == '1');
if (ch == '0') s0[i][j] = true;
else s1[i][j] = true;
}
}
F(i, 1, m) F(c, 0, 1) {
ss0.set(); ss1.set();
F(j, 1, n)
if (st[j][i] == c) {
ss0 &= s0[j];
ss1 &= s1[j];
}
F(j, 1, m) {
if (ss0[j]) t[c << 1][i][j] = true;
if (ss1[j]) t[c << 1 | 1][i][j] = true;
}
}
F(i, 1, m)
F(j, i, m)
F(k, 0, 3)
if (t[k ^ 2][i][j] && t[cc[k] ^ 2][j][i]) {
if (!(i == j && (k != 0 && k != 3))) {
int a = (k >> 1) & 1, b = k & 1;
// cout << k << " " << i << " " << j << endl;
v[(a ^ 1) * m + i].push_back(b * m + j);
v[(b ^ 1) * m + j].push_back(a * m + i);
ans.emplace_back(k, make_pair(i, j));
}
}
F(i, 1, m * 2)
if (!sccnum[i]) tarjan(i);
F(i, 1, m * 2) sccnum[i] = scccnt - sccnum[i] + 1;
F(i, 1, m * 2)
for (int j: v[i])
if (sccnum[i] != sccnum[j])
v2[sccnum[i]].push_back(sccnum[j]);
F(i, 1, m) {
if (sccnum[i] == sccnum[i + m]) return puts("-1"), 0;
if (sccnum[i] > sccnum[i + m]) swap(sccnum[i], sccnum[i + m]);
// ook[sccnum[i]][sccnum[i + m]] = true;
ook[sccnum[i + m]][sccnum[i]] = true;
// chk[sccnum[i + m]].push_back(sccnum[i]);
// chk2[sccnum[i]].push_back(sccnum[i + m]);
// chk2[sccnum[i + m]].push_back(sccnum[i]);
}
DF(i, scccnt, 1) {
for (int j: v2[i]) ok[i] |= ok[j];
ok[i][i] = true;
// F(j, 1, scccnt)
// if (ok[i][j]) tt[i].push_back(j);
}
// if (n == 2000) return 0;
bitset <N * 2> t; t.reset();
solve(1, t);
assert(nn == n);
writeln(ans.size());
for (auto [i, j]: ans) writes(j.first - 1), writes(j.second - 1), writeln(cc[i] + 1);
pc(0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 15824kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #2:
score: -100
Dangerous Syscalls
input:
3 3 101 011 111