結果
問題 | No.1060 素敵な宝箱 |
ユーザー |
![]() |
提出日時 | 2020-09-06 14:08:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 1,819 bytes |
コンパイル時間 | 1,448 ms |
コンパイル使用メモリ | 131,492 KB |
最終ジャッジ日時 | 2025-01-14 07:45:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #include <list> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair<int, int>; template <typename T, typename S> ostream& operator<<(ostream& os, pair<T, S> a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template <typename T> ostream& operator<<(ostream& os, vector<T> v) { for (auto x : v) os << x << ' '; return os; } void debug() { cerr << '\n'; } template <typename H, typename... T> void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } ll a[305][305]; int main(){ int n, m; cin >> n >> m; rep(i,n)rep(j,m)cin >> a[i][j]; ll s[305] = {}; rep(i,n)rep(j,m)s[j] += a[i][j]; vector<pair<ll,int>> v; rep(i,n){ ll sum = 0; rep(j,m){ sum += 2 * a[i][j] * s[j]; } v.emplace_back(sum, i); } sort(v.rbegin(), v.rend()); ll ans = 0; ll c[305] = {}; ll d[305] = {}; rep(i,n){ rep(j,m){ if(i % 2 == 0){ c[j] += a[v[i].second][j]; }else{ d[j] += a[v[i].second][j]; } } } rep(j,m){ ans += c[j] * c[j]; ans -= d[j] * d[j]; } cout << ans << endl; }