Submission #3448720
Source Code Expand
#include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <numeric> #include <set> #include <map> #include <stack> #include <queue> #include <time.h> #include <list> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define reps(x,c) for(auto x:c) #define all(x) begin(x), end(x) #define pb(a) emplace_back(a) #define mp(a,b) make_pair((a),(b)) #define pl pair<ll,ll> #define INF 2147483600 #define MOD 1000000007 #define fi first #define se second #define dbg(x) cout << #x"="<< (x) << endl #define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl ll D[1010][1010],C[510][510]; int main(){ ll n,c;cin>>n>>c; rep(i,c){ rep(j,c){ cin>>D[i][j]; } } rep(i,n){ rep(j,n){ cin>>C[i][j]; } } vector<pl> v0(c); vector<pl> v1(c); vector<pl> v2(c); rep(i,c){ v0[i].se=i; v1[i].se=i; v2[i].se=i; rep(j,n){ rep(k,n){ if((j+k+2)%3==0){ v0[i].fi+=D[C[j][k]-1][i]; }else if((j+k+2)%3==1){ v1[i].fi+=D[C[j][k]-1][i]; }else{ v2[i].fi+=D[C[j][k]-1][i]; } } } } sort(all(v0)); sort(all(v1)); sort(all(v2)); ll ans=INF; rep(i,3){ rep(j,3){ rep(k,3){ if(v0[i].se!=v1[j].se&&v0[i].se!=v2[k].se&&v1[j].se!=v2[k].se){ ans=min(ans,v0[i].fi+v1[j].fi+v2[k].fi); } } } } cout<<ans<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Good Grid |
User | motigome |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1563 Byte |
Status | AC |
Exec Time | 63 ms |
Memory | 4352 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, sample_01.txt, sample_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 61 ms | 4352 KB |
02.txt | AC | 48 ms | 4096 KB |
03.txt | AC | 1 ms | 2304 KB |
04.txt | AC | 16 ms | 3328 KB |
05.txt | AC | 2 ms | 2304 KB |
06.txt | AC | 63 ms | 4352 KB |
07.txt | AC | 61 ms | 4352 KB |
08.txt | AC | 61 ms | 4224 KB |
09.txt | AC | 14 ms | 3328 KB |
10.txt | AC | 6 ms | 2944 KB |
11.txt | AC | 11 ms | 3200 KB |
12.txt | AC | 17 ms | 3584 KB |
13.txt | AC | 60 ms | 4224 KB |
14.txt | AC | 45 ms | 4096 KB |
15.txt | AC | 61 ms | 4352 KB |
16.txt | AC | 26 ms | 3584 KB |
sample_01.txt | AC | 1 ms | 2304 KB |
sample_02.txt | AC | 1 ms | 2304 KB |