QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624153 | #7925. Chayas | taiyangfeng | WA | 384ms | 135648kb | C++20 | 3.9kb | 2024-10-09 15:06:47 | 2024-10-09 15:06:49 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef LOCAL
#define debug(...) printf(__VA_ARGS__)
#define edebug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define edebug(...)
#endif
#define int ll
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define nrep(i, x, y) for(int i = x; i >= y; --i)
#define ll long long
#define pii std::pair<int,int>
#define pb emplace_back
#define fi first
#define se second
template <class T>
inline void ckmax(T &a, T b) {
if(a < b) a = b;
}
template <class T>
inline void ckmin(T &a, T b) {
if(a > b) a = b;
}
auto rt_YES = []{puts("YES");};
auto rt_Yes = []{puts("Yes");};
auto rt_NO = []{puts("NO");};
auto rt_No = []{puts("No");};
namespace IO {
#define isdigit(x) (x >= '0' && x <= '9')
inline char gc() {
return getchar();
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline void read(T &x) {
double tmp = 1;
bool sign = 0;
x = 0;
char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc())
x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
inline void read(char *s) {
char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc())
*s++ = ch;
*s = 0;
}
inline void read(char &c) {
for(c = gc(); blank(c); c = gc());
}
inline void push(const char &c) {
putchar(c);
}
template <class T>
inline void print(T x) {
if(x < 0) {
x = -x;
push('-');
}
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top)
push(sta[--top] + '0');
}
template <class T>
inline void print(T x, char lastChar) {
print(x);
push(lastChar);
}
}
using namespace IO;
constexpr int mod=9983244353;
int n,m;
int a[20000],b[20000],c[20000];
bool f[24][16777216];
signed g[16777216];
int A[2][24],color[24],vis[24];
std::vector<int>e[24];
int dfs(int u,int c){
// debug("dfs %lld %lld\n",u,c);
vis[u]=1;
int S=0;
if(c)S=(1<<u);
for(int i:e[u]){
// debug("go %lld %lld\n",i,color[i]);
if(color[i]!=-1&&color[i]!=c)return -1;
if(color[i]==-1){
color[i]=c;
int T=dfs(i,c^1);
if(T==-1)return -1;
S|=T;
}
}
return S;
}
signed main() {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//------------------------------------------------------------------
read(n),read(m);
rep(i,1,m)read(a[i]),read(b[i]),read(c[i]),a[i]--,b[i]--,c[i]--;
rep(i,0,n-1){
rep(j,0,n-1)e[j].clear();
memset(A,0,sizeof(A));
memset(vis,0,sizeof(vis));
rep(j,1,m)if(b[j]==i)e[a[j]].pb(c[j]),e[c[j]].pb(a[j]);
int sum=0;
std::vector<int>S,T;//S.pb(0);
rep(j,0,n-1)if(j!=i&&!vis[j]){
++sum;
memset(color,-1,sizeof(color));
int t=dfs(j,0);
if(t==-1){puts("0");return 0;}
A[0][sum-1]=t;
memset(color,-1,sizeof(color));
t=dfs(j,1);
A[1][sum-1]=t;
// debug("%lld %lld\n",A[0][sum-1],A[1][sum-1]);
if(sum==1)S.pb(A[0][sum-1]),S.pb(A[1][sum-1]);
else{
for(int k:S){
T.pb(k|A[0][sum-1]);
T.pb(k|A[1][sum-1]);
}
// for(int i:T)S.pb(i);
S.swap(T);
T.clear();
}
}
for(int k:S){
f[i][k]=1;
// print(k,' ');
}//puts("");
}
g[0]=1;
rep(i,0,(1<<n)-1)rep(j,0,n-1)if(f[j][i])
g[i|(1<<j)]+=g[i],g[i|(1<<j)]%=mod;
print(g[(1<<n)-1]);
//------------------------------------------------------------------
end:
std::cerr << "Time : " << clock() - c1 << " ms" << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13852kb
input:
5 4 1 2 4 2 3 5 3 2 4 1 3 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 14104kb
input:
4 2 3 1 4 1 4 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 13864kb
input:
5 5 3 1 2 2 5 4 5 4 3 3 1 5 1 4 5
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 3ms
memory: 18040kb
input:
6 6 1 6 3 2 3 4 5 6 4 3 5 1 1 3 4 1 2 4
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 0ms
memory: 18052kb
input:
7 10 5 1 6 2 4 7 3 1 2 4 5 7 5 2 6 7 3 6 7 4 6 2 5 7 4 3 7 6 2 3
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 2ms
memory: 22308kb
input:
9 12 8 1 5 6 1 2 4 2 3 2 9 3 1 6 3 7 9 5 4 2 8 3 8 2 6 7 3 4 2 7 3 7 1 7 5 2
output:
28
result:
ok single line: '28'
Test #7:
score: 0
Accepted
time: 0ms
memory: 28508kb
input:
12 15 10 8 7 2 10 9 4 9 3 5 2 6 7 12 10 10 3 5 4 6 10 9 11 1 12 4 6 8 1 3 6 11 2 3 2 11 4 6 1 4 6 11 7 4 5
output:
128
result:
ok single line: '128'
Test #8:
score: 0
Accepted
time: 92ms
memory: 68700kb
input:
20 20 7 16 19 18 14 9 4 5 7 2 20 4 19 13 17 4 8 16 5 2 6 11 17 9 1 15 11 18 10 9 8 12 11 4 1 9 3 11 13 15 18 4 3 9 2 14 4 19 14 3 9 11 6 1 13 14 3 19 11 7
output:
115058708
result:
ok single line: '115058708'
Test #9:
score: 0
Accepted
time: 138ms
memory: 81340kb
input:
21 40 17 7 12 12 11 8 18 19 20 3 12 4 20 5 15 5 16 8 18 11 4 17 5 15 9 20 4 8 2 6 15 14 7 18 13 11 12 9 17 9 1 10 18 2 11 12 17 13 3 21 6 4 15 6 19 2 6 21 8 13 4 1 8 21 4 11 1 2 7 6 10 4 14 5 15 16 14 15 15 7 9 19 12 3 6 11 8 8 9 7 18 6 12 4 19 18 3 21 9 1 2 3 3 5 1 17 1 4 17 16 15 13 10 21 18 13 2 ...
output:
131696
result:
ok single line: '131696'
Test #10:
score: -100
Wrong Answer
time: 384ms
memory: 135648kb
input:
22 25 2 6 17 19 16 10 6 20 4 4 1 16 17 21 11 16 8 5 14 3 12 17 9 4 7 19 17 14 2 18 22 12 19 10 13 19 4 18 12 16 11 20 4 15 13 7 22 12 17 11 2 20 7 19 17 21 2 4 14 5 14 5 6 13 18 20 18 3 11 2 10 3 14 19 17
output:
112670920
result:
wrong answer 1st lines differ - expected: '188168263', found: '112670920'