Submission #4307803
Source Code Expand
#include "bits/stdc++.h" typedef long long ll; #define int ll #define fi first #define se second #define SORT(a) sort(a.begin(),a.end()) #define rep(i,n) for(int i = 0;i < (n) ; i++) #define REP(i,n) for(int i = 0;i < (n) ; i++) #define MP(a,b) make_pair(a,b) #define pb(a) push_back(a) #define INF LLONG_MAX/2 using namespace std; int MOD = 1000000007; int kai[100010] = {0}; signed main(){ int n; cin >> n; kai[0] = kai[1] = 1; for(int i = 2;i <= n;i++){ kai[i] = i*kai[i-1]; kai[i] %= MOD; } set<pair<int,int>> s; rep(i,n){ int a; cin >> a; s.insert(MP(a,0)); } rep(i,n){ int a; cin >> a; s.insert(MP(a,1)); } // for(auto x:s) cerr << x.fi << " " << x.se << endl; int p[2] = {0}; int prev = -1; int cnt = 0; int ans = 1; for(auto x:s){ if(prev == -1){ prev = x.se; p[x.se]++; cnt++; }else{ if(prev == x.se && (p[(prev+1)%2] == 0 || p[(prev+1)%2] > p[prev])){ cerr << " "; p[prev]++; }else if(prev != x.se && p[x.se] == 0){ p[x.se]++; prev = x.se; }else if(p[0] == p[1] && p[0] > 0){ ans *= kai[p[0]]; ans %= MOD; p[0] = 0; p[1] = 0; prev = x.se; p[x.se]++; } cnt++; } cerr << cnt << " " << p[0] << " " << p[1] << " " << ans << endl; } ans *= kai[p[0]]; ans %= MOD; cout << ans << endl; return 0; } // g++ -std=c++14 code1.cpp // rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a // rm -r -f test;oj dl http://cf16-exhibition-final-open.contest.atcoder.jp/tasks/cf16_exhibition_final_a
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | Shibungi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1950 Byte |
Status | WA |
Exec Time | 889 ms |
Memory | 15616 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 | 519 ms | 8320 KB |
001.txt | WA | 180 ms | 3200 KB |
002.txt | WA | 256 ms | 4352 KB |
003.txt | WA | 281 ms | 4736 KB |
004.txt | WA | 783 ms | 12032 KB |
005.txt | WA | 873 ms | 13568 KB |
006.txt | WA | 866 ms | 13568 KB |
007.txt | WA | 878 ms | 15616 KB |
008.txt | WA | 879 ms | 13568 KB |
009.txt | WA | 885 ms | 13568 KB |
010.txt | AC | 889 ms | 13568 KB |
011.txt | AC | 842 ms | 13568 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 1 ms | 256 KB |