結果
問題 |
No.1470 Mex Sum
|
ユーザー |
![]() |
提出日時 | 2021-04-09 21:35:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,354 bytes |
コンパイル時間 | 1,253 ms |
コンパイル使用メモリ | 161,208 KB |
実行使用メモリ | 11,676 KB |
最終ジャッジ日時 | 2024-06-25 04:29:15 |
合計ジャッジ時間 | 18,522 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 TLE * 1 -- * 38 |
コンパイルメッセージ
main.cpp: In function ‘long long int f(int, int)’: main.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type] 25 | } | ^
ソースコード
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair<int,int> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; ll f(int a, int b){ REP(i, 5){ if(i != a && i != b){ return i; break; } } } int main() { int n; cin >> n; vector<ll> a(n); rep(i, n)cin >> a[i]; ll one = 0, two = 0, el; ll cnt = 0, ans = 0; rep(i, n)one += (a[i] == 1); rep(i, n)two += (a[i] == 2); el = n - one - two; //mex(a_i, a_j) = 2 cnt += one*(one-1)/2; ans += one*(one-1); cnt += one*el; ans += one*el*2; //mex(a_i, a_j) = 3 cnt += one*two; ans += one*two*3; //mex(a_i, a_j) = 1 ans += n*(n-1)/2-cnt; //cout << ans << endl; ll sum = 0; rep(i, n)rep(j, n){ if(i <= j)continue; sum += f(a[i], a[j]); } cout << sum << endl; }