Submission #1003139
Source Code Expand
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cassert> #include <cmath> #include <string> #include <queue> #include <set> #include <map> #include <cstdlib> using namespace std; #define TASKNAME "" void solve(int test_number); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.setf(ios::fixed); cout.precision(9); cerr.setf(ios::fixed); cerr.precision(3); #ifdef LOCAL freopen("test.in", "r", stdin); freopen("test.out", "w", stdout); #else #endif int n = 1; for (int i = 0; i < n; i++) { solve(i); } } const int MAX_N = 100005; const int MOD = 1000000007; int n, a[MAX_N], b[MAX_N], fact[MAX_N]; void solve(int test_number) { cin >> n; /* srand(time(0)); n = 7; bool used[100] = {false}; int val[100], sz = 0; for (int i = 0; i < n; i++) { int x; do { x = rand() % 100; } while (used[x]); used[x] = true; a[i] = x; val[sz++] = x; } for (int i = 0; i < n; i++) { int x; do { x = rand() % 100; } while (used[x]); used[x] = true; b[i] = x; val[sz++] = x; } sort(val, val + sz); sz = unique(val, val + sz) - val; */ for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + n); /* for (int i = 0; i < n; i++) { a[i] = lower_bound(val, val + sz, a[i]) - val; cout << a[i] << " "; } cout << endl; for (int i = 0; i < n; i++) { b[i] = lower_bound(val, val + sz, b[i]) - val; cout << b[i] << " "; } cout << endl; int min_ans = 0; for (int i = 0; i < n; i++) { min_ans += abs(a[i] - b[i]); } cout << "MIN ANS: " << min_ans << endl; int perm[12]; for (int i = 0; i < n; i++) { perm[i] = i; } int brute_ans = 0; do { int cur_ans = 0; for (int i = 0; i < n; i++) { cur_ans += abs(a[i] - b[perm[i]]); } if (cur_ans == min_ans) { for (int j = 0; j < n; j++) { cout << perm[j] << " "; } cout << endl; brute_ans++; } } while (next_permutation(perm, perm + n)); cout << "BRUTE ANS : " << brute_ans << endl; */ int ans = 1; int var = 0; int i = 0, j = 0; while (i < n || j < n) { if (var == 0 && (i == n || a[i] < b[j])) { swap(a, b); swap(i, j); } while (j < n && b[j] < a[i]) { var++; j++; } i++; ans = ans * max(1, var) % MOD; var--; } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | Sarkin |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2957 Byte |
Status | WA |
Exec Time | 2102 ms |
Memory | 1024 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 28 ms | 1024 KB |
001.txt | WA | 18 ms | 1024 KB |
002.txt | WA | 29 ms | 1024 KB |
003.txt | WA | 25 ms | 1024 KB |
004.txt | WA | 57 ms | 1024 KB |
005.txt | WA | 81 ms | 1024 KB |
006.txt | WA | 62 ms | 1024 KB |
007.txt | WA | 62 ms | 1024 KB |
008.txt | WA | 50 ms | 1024 KB |
009.txt | WA | 63 ms | 1024 KB |
010.txt | WA | 36 ms | 1024 KB |
011.txt | TLE | 2102 ms | 1024 KB |
example0.txt | AC | 4 ms | 1024 KB |
example1.txt | AC | 4 ms | 1024 KB |