Submission #4005610


Source Code Expand

Copy
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[2000],b[2000];
int c[2000][2000];
int a1[2000000],b1[2000000];
ll sum[2000000];

int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n)scanf("%d",&a[i]),a1[a[i]]++;
	rep(i,m)scanf("%d",&b[i]),b1[b[i]]++;
	for(int i=1;i<=n*m;i++){
		if(a1[i]>1||b1[i]>1){
			puts("0");return 0;
		}
	}
	memset(c,0x3f,sizeof(c));
	int ax=-1,ay=-1;
	rep(i,n)rep(j,m){
		c[i][j]=min(a[i],b[j]);
		if(c[i][j]==n*m){
			if(ax!=-1){
				puts("0");return 0;
			}
			ax=i;ay=j;
		}
	}
	if(ax==-1&&ay==-1){
		puts("0");return 0;
	}
	ll ans=1;
	ll c1=1,c2=1;
	for(int i=n*m-1;i>=1;i--){
		ll cnt=n*m-i;
		//~ ll A=n*m-c1*m,B=n*m-c2*n;
		if(a1[i]&&b1[i]){
			(ans*=1)%=MOD;
		}
		if(a1[i]&&!b1[i]){
			(ans*=c2)%=MOD;
		}
		if(!a1[i]&&b1[i]){
			(ans*=c1)%=MOD;
		}
		if(!a1[i]&&!b1[i]){
			(ans*=(c1*c2-cnt))%=MOD;
		}
		if(a1[i])c1++;
		if(b1[i])c2++;
	}
	cout<<ans%MOD<<endl;
}

Submission Info

Submission Time
Task D - Double Landscape
User autumn_eel
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1122 Byte
Status
Exec Time 13 ms
Memory 20480 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:16:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n,m;scanf("%d%d",&n,&m);
                             ^
./Main.cpp:17:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i,n)scanf("%d",&a[i]),a1[a[i]]++;
                                      ^
./Main.cpp:18:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i,m)scanf("%d",&b[i]),b1[b[i]]++;
                                      ^

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt, s4.txt
All 500 / 500 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt 12 ms 20480 KB
02.txt 12 ms 20480 KB
03.txt 13 ms 20480 KB
04.txt 12 ms 20480 KB
05.txt 13 ms 20480 KB
06.txt 12 ms 20480 KB
07.txt 13 ms 20480 KB
08.txt 13 ms 20480 KB
09.txt 13 ms 20480 KB
10.txt 13 ms 20480 KB
11.txt 12 ms 20480 KB
12.txt 13 ms 20480 KB
13.txt 13 ms 20480 KB
14.txt 8 ms 20480 KB
15.txt 8 ms 20480 KB
16.txt 13 ms 20480 KB
17.txt 13 ms 20480 KB
18.txt 13 ms 20480 KB
19.txt 13 ms 20480 KB
20.txt 13 ms 20480 KB
21.txt 13 ms 20480 KB
22.txt 13 ms 20480 KB
23.txt 13 ms 20480 KB
24.txt 13 ms 20480 KB
25.txt 13 ms 20480 KB
26.txt 13 ms 20480 KB
27.txt 13 ms 20480 KB
28.txt 13 ms 20480 KB
29.txt 13 ms 20480 KB
30.txt 13 ms 20480 KB
s1.txt 6 ms 20480 KB
s2.txt 6 ms 20480 KB
s3.txt 2 ms 4352 KB
s4.txt 6 ms 20480 KB