結果
問題 | No.1324 Approximate the Matrix |
ユーザー |
![]() |
提出日時 | 2020-12-21 23:08:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,916 bytes |
コンパイル時間 | 1,150 ms |
コンパイル使用メモリ | 127,844 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-21 13:12:56 |
合計ジャッジ時間 | 2,501 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 32 |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } int main(){ int n,k; cin >> n >> k; vector<int> a(n); rep(i,n) cin >> a[i]; vector<int> b(n); rep(i,n) cin >> b[i]; vector<vector<int> > p(n,vector<int>(n)); priority_queue<pair<int,pair<int,int> > > pq; rep(i,n){ rep(j,n){ cin >> p[i][j]; pq.push(MP(p[i][j],MP(i,j))); } } vector<vector<int> > res(n,vector<int>(n)); while(!pq.empty()){ auto x = pq.top(); pq.pop(); int i = x.second.first; int j = x.second.second; if(a[i]>0&&b[j]>0){ a[i]--; b[j]--; res[i][j]++; pq.push(MP(x.first-1,MP(i,j))); } } ll ans =0; rep(i,n){ rep(j,n){ ans += (res[i][j]-p[i][j])*(res[i][j]-p[i][j]); } } cout << ans << endl; return 0; }