Submission #4049128
Source Code Expand
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define MAX_N (100000L)
#define NUM_MOD (1000000007L)
using namespace std;
int main(int argc, char *argv[]) {
// read inputs
long N, as[MAX_N], bs[MAX_N];
scanf("%ld", &N);
for (long i = 0; i < N; i++) {
scanf("%ld", &as[i]);
}
for (long i = 0; i < N; i++) {
scanf("%ld", &bs[i]);
}
// NOTE : modified input
sort(as, as + N);
sort(bs, bs + N);
// solve
long ia = 0, ib = 0, num = 0, ans = 1;
while (ia < N && ib < N) {
if (as[ia] <= bs[ib]) {
if (num < 0) {
ans = (ans * abs(num)) % NUM_MOD;
}
num++;
ia++;
} else {
if (num > 0) {
ans = (ans * abs(num)) % NUM_MOD;
}
num--;
ib++;
}
// printf("ia = %ld, ib = %ld, num = %ld, ans = %ld\n", ia, ib, num, ans);
}
while (ia < N) {
if (num < 0) {
ans = (ans * abs(num)) % NUM_MOD;
}
num++;
ia++;
// printf("ia = %ld, ib = %ld, num = %ld, ans = %ld\n", ia, ib, num, ans);
}
while (ib < N) {
if (num > 0) {
ans = (ans * abs(num)) % NUM_MOD;
}
num--;
ib++;
// printf("ia = %ld, ib = %ld, num = %ld, ans = %ld\n", ia, ib, num, ans);
}
printf("%ld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
A - 1D Matching |
User |
khir |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
1315 Byte |
Status |
AC |
Exec Time |
36 ms |
Memory |
1664 KB |
Compile Error
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:13:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%ld", &N);
^
./Main.cpp:15:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%ld", &as[i]);
^
./Main.cpp:18:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%ld", &bs[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, example0.txt, example1.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
AC |
22 ms |
1152 KB |
001.txt |
AC |
8 ms |
512 KB |
002.txt |
AC |
11 ms |
640 KB |
003.txt |
AC |
12 ms |
768 KB |
004.txt |
AC |
32 ms |
1536 KB |
005.txt |
AC |
36 ms |
1664 KB |
006.txt |
AC |
36 ms |
1664 KB |
007.txt |
AC |
36 ms |
1664 KB |
008.txt |
AC |
36 ms |
1664 KB |
009.txt |
AC |
36 ms |
1664 KB |
010.txt |
AC |
36 ms |
1664 KB |
011.txt |
AC |
36 ms |
1664 KB |
example0.txt |
AC |
1 ms |
128 KB |
example1.txt |
AC |
1 ms |
128 KB |