Submission #1712936


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

const int mod = 1000*1000*1000+7;

int N;
vector<int> A, B;

int main() {
    scanf("%d", &N);

    A.resize(N);
    B.resize(N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for(int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    int ans = 1;

    for(int i = N - 1; i >= 0; i--) {
        int s = i + 1, e = N - 1;
        int p = i;

        while(s <= e) {
            int m = (s + e)>>1;

            if(A[m] <= B[i]) {
                p = m;
                s = m + 1;
            }
            else e = m - 1;
        }
        s = i + 1, e = N - 1;
        int q = i;
        while(s <= e) {
            int m = (s + e)>>1;
            
            if(B[m] <= A[i]) {
                q = m;
                s = m + 1;
            }
            else e = m + 1;
        }

        ans = 1LL * ans * (max(p, q) - i + 1) % mod;
    }

    cout << ans;
}

Submission Info

Submission Time
Task A - 1D Matching
User choikiwon
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1060 Byte
Status TLE
Exec Time 2103 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:10:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
./Main.cpp:16:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
                           ^
./Main.cpp:19:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &B[i]);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
TLE × 2
AC × 1
TLE × 13
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 TLE 2103 ms 768 KB
001.txt TLE 2103 ms 384 KB
002.txt TLE 2103 ms 512 KB
003.txt TLE 2103 ms 512 KB
004.txt TLE 2103 ms 896 KB
005.txt TLE 2103 ms 1024 KB
006.txt TLE 2103 ms 1024 KB
007.txt TLE 2103 ms 1024 KB
008.txt TLE 2103 ms 1024 KB
009.txt TLE 2103 ms 1024 KB
010.txt AC 40 ms 1024 KB
011.txt TLE 2103 ms 1024 KB
example0.txt TLE 2103 ms 256 KB
example1.txt TLE 2103 ms 256 KB