結果
問題 | No.1279 Array Battle |
ユーザー | idat_50me |
提出日時 | 2020-11-06 21:31:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 2,839 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 175,252 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 12:16:54 |
合計ジャッジ時間 | 2,514 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T, typename U> using vp = vector<pair<T,U>>; template<typename T> using pque = priority_queue<T>; template<typename T> using lpque = priority_queue<T,vector<T>,greater<T>>; using ll = long long; using pint = pair<int,int>; using pll = pair<ll,ll>; using pil = pair<int,ll>; using pli = pair<ll,int>; using vint = vector<int>; using vll = vector<ll>; using qint = queue<int>; using pqint = pque<int>; using qll = queue<ll>; using pqll = pque<ll>; #define PI 3.141592653589793 #define INTINF ((1<<30)-1) #define LLINF ((1LL<<62)-1) #define MPRIME 1000000007 #define MPRIME9 998244353 #define MMPRIME ((1ll<<61)-1) #define len length() #define pushb push_back #define fi first #define se second const char newl = '\n'; #define all(name) name.begin(),name.end() #define rall(name) name.rbegin(),name.rend() #define gsort(vbeg,vend) sort(vbeg,vend,greater<>()) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline void init(T& v) { for(auto &a: v) cin>>a; } template<class T, class U> inline void init(vector<pair<T,U>>& v) { for(auto &a: v) cin>>a.first>>a.second; } template<class T, class N> inline void init(T& v, N n) { v.resize(n); for(auto &a: v) cin>>a; } template<class T, class U, class N> inline void init(vector<pair<T,U>>& v, N n) { v.resize(n); for(auto &a: v) cin>>a.first>>a.second; } template<class T> inline void out(T a) { cout<<a<<endl; } template<class T, class... U> inline void out(T a, U... alist) { cout<<a<<" "; out(forward<U>(alist)...); } template<class N> void resiz(N n) { //empty } template<class N, class T, class... U> void resiz(N n, T&& hd, U&&... tl) { hd.resize(n); resiz(n,forward<U>(tl)...); } ll binpow(ll a, ll ex, ll p) { ll result=1; while(ex>0) { if(ex&1) result=result*a%p; ex>>=1; a=a*a%p; } return result; } ll factorial(int x, ll p=(1LL<<62)-1) { ll res = 1; for(int i=2; i<=x; i++) res = res * i % p; return res; } int N, ans=-1, n=0; vint A,B; void input() { cin>>N; init(A,N); init(B,N); } void solve() { sort(all(A)); do { int tmp=0; for(int i=0; i<N; i++) { if(A[i]>B[i]) tmp += A[i]-B[i]; } chmax(ans,tmp); }while(next_permutation(all(A))); do { int tmp=0; for(int i=0; i<N; i++) { if(A[i]>B[i]) tmp += A[i]-B[i]; } if(ans==tmp) n++; }while(next_permutation(all(A))); int z=1; for(int i=1; i<N; i++) { if(A[i-1]==A[i]) z++; if(A[i-1]!=A[i] || i==N-1) { n *= factorial(z); z=1; } } cout<<n<<newl; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(15); int t=1; while(t) { input(); solve(); t--; } }