Submission #17759510
Source Code Expand
Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
int N,K;
int A[51][51];
const ll mo=998244353;
template<int um> class UF {
public:
vector<int> par,rank,cnt;
UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
int count(int x) { return cnt[operator[](x)];}
int operator()(int x,int y) {
if((x=operator[](x))==(y=operator[](y))) return x;
cnt[y]=cnt[x]=cnt[x]+cnt[y];
if(rank[x]>rank[y]) return par[x]=y;
rank[x]+=rank[x]==rank[y]; return par[y]=x;
}
};
UF<51> UFR,UFC;
ll fact[55];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>K;
FOR(y,N) FOR(x,N) cin>>A[y][x];
fact[0]=1;
for(i=1;i<=50;i++) fact[i]=fact[i-1]*i%mo;
int y1,y2,x1,x2;
FOR(y2,N) FOR(y1,y2) {
int ok=1;
FOR(x,N) if(A[y1][x]+A[y2][x]>K) ok=0;
if(ok) UFR(y1,y2);
}
FOR(x2,N) FOR(x1,x2) {
int ok=1;
FOR(y,N) if(A[y][x1]+A[y][x2]>K) ok=0;
if(ok) UFC(x1,x2);
}
ll ret=1;
FOR(i,N) {
if(UFR[i]==i) ret=ret*fact[UFR.count(i)]%mo;
if(UFC[i]==i) ret=ret*fact[UFC.count(i)]%mo;
}
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
Submission Info
Submission Time |
|
Task |
C - Shuffle Permutation |
User |
kmjp |
Language |
C++ (GCC 9.2.1) |
Score |
500 |
Code Size |
1931 Byte |
Status |
AC |
Exec Time |
6 ms |
Memory |
3648 KB |
Compile Error
./Main.cpp: In function ‘void solve()’:
./Main.cpp:38:8: warning: unused variable ‘j’ [-Wunused-variable]
38 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp:38:10: warning: unused variable ‘k’ [-Wunused-variable]
38 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp:38:12: warning: unused variable ‘l’ [-Wunused-variable]
38 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp:38:14: warning: unused variable ‘r’ [-Wunused-variable]
38 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:7:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
7 | #define FOR(x,to) for(x=0;x<(to);x++)
| ^
./Main.cpp:70:38: note: in expansion of macro ‘FOR’
70 | FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
| ^~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00, example_01 |
All |
example_00, example_01, handmade_00, handmade_01, max_random2_00, max_random2_01, max_random2_02, max_random2_03, max_random2_04, max_random2_05, max_random2_06, max_random_00, max_random_01, max_random_02, random_00, random_01, random_02, small2_00, small2_01, small2_02, small2_03, small2_04, small_00, small_01, small_02 |
Case Name |
Status |
Exec Time |
Memory |
example_00 |
AC |
6 ms |
3572 KB |
example_01 |
AC |
2 ms |
3584 KB |
handmade_00 |
AC |
2 ms |
3500 KB |
handmade_01 |
AC |
2 ms |
3620 KB |
max_random2_00 |
AC |
3 ms |
3628 KB |
max_random2_01 |
AC |
2 ms |
3580 KB |
max_random2_02 |
AC |
3 ms |
3632 KB |
max_random2_03 |
AC |
2 ms |
3628 KB |
max_random2_04 |
AC |
2 ms |
3508 KB |
max_random2_05 |
AC |
2 ms |
3580 KB |
max_random2_06 |
AC |
2 ms |
3604 KB |
max_random_00 |
AC |
2 ms |
3580 KB |
max_random_01 |
AC |
2 ms |
3472 KB |
max_random_02 |
AC |
2 ms |
3584 KB |
random_00 |
AC |
2 ms |
3508 KB |
random_01 |
AC |
2 ms |
3508 KB |
random_02 |
AC |
2 ms |
3588 KB |
small2_00 |
AC |
2 ms |
3588 KB |
small2_01 |
AC |
2 ms |
3612 KB |
small2_02 |
AC |
2 ms |
3584 KB |
small2_03 |
AC |
2 ms |
3648 KB |
small2_04 |
AC |
2 ms |
3576 KB |
small_00 |
AC |
2 ms |
3628 KB |
small_01 |
AC |
2 ms |
3648 KB |
small_02 |
AC |
2 ms |
3608 KB |