結果

問題 No.1564 Sum of Products of Pairs
ユーザー kpinkcatkpinkcat
提出日時 2023-09-11 20:29:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,029 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 199,892 KB
実行使用メモリ 8,212 KB
最終ジャッジ日時 2023-09-11 20:29:47
合計ジャッジ時間 6,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0