結果
問題 |
No.1564 Sum of Products of Pairs
|
ユーザー |
![]() |
提出日時 | 2023-09-11 20:29:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,029 bytes |
コンパイル時間 | 1,626 ms |
コンパイル使用メモリ | 195,648 KB |
最終ジャッジ日時 | 2025-02-16 21:43:12 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 29 |
ソースコード
#include <bits/stdc++.h> #include<iostream> #include<map> #include<vector> #include <algorithm> #include<math.h> #include <iomanip> #include<set> #include <numeric> #include<string> using ll = long long; using namespace std; int main() { ll n, dif, min1 = 0, sum1 = 0; cin >> n; vector<int> a(2*n+1); for (int i = 1; i <= 2*n; i++){ cin >> a[i]; if (!(i%2)) sum1 += a[i-1]*a[i]; } for (int i = 1; i < 2*n; i++){ for (int j = i+1; j <= 2*n; j++){ if ((i%2) && (j == i+1)) continue; if (!(i%2) && !(j%2)) dif = (a[i-1] * a[i] + a[j-1]*a[j]) - (a[i-1]*a[j] + a[j-1]*a[i]); else if (!(i%2) && (j%2)) dif = (a[i-1] * a[i] + a[j]*a[j+1]) - (a[i-1]*a[j] + a[i]*a[j+1]); else if ((i%2) && !(j%2)) dif = (a[i] * a[i+1] + a[j-1]*a[j]) - (a[j]*a[i+1] + a[j-1]*a[i]); else dif = (a[i] * a[i+1] + a[j]*a[j+1]) - (a[j]*a[i+1] + a[i]*a[j+1]); if (min1 > dif) min1 = dif; } } cout << sum1 - min1 << endl; }