Submission #3444601


Source Code Expand

#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,C;
  cin >> N >> C ;
  vvl d(C,vl(C)),c(N,vl(N)),cost(3,vl(C));
  rep(i,C) rep(j,C) cin >> d[i][j] ;
  rep(i,N) rep(j,N) cin >> c[i][j] ;
  rep(mm,3) rep(color,C){
    rep(i,N) rep(j,N){
      if((i+j)%3!=mm) continue;
      cost[mm][color] += d[c[i][j]-1][color];
    }
  }
  ll ans = LINF;
  rep(x,C) rep(y,C){
    if(x==y) continue;
    rep(z,C){
      if(z==x||z==y) continue;
      chmin(ans,cost[0][x]+cost[1][y]+cost[2][z]);
    }
  }
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task D - Good Grid
User kurarrr
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2678 Byte
Status AC
Exec Time 53 ms
Memory 2304 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 18
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 53 ms 2304 KB
02.txt AC 41 ms 1792 KB
03.txt AC 1 ms 256 KB
04.txt AC 10 ms 896 KB
05.txt AC 1 ms 256 KB
06.txt AC 52 ms 2304 KB
07.txt AC 53 ms 2304 KB
08.txt AC 52 ms 2176 KB
09.txt AC 9 ms 768 KB
10.txt AC 5 ms 512 KB
11.txt AC 7 ms 640 KB
12.txt AC 9 ms 896 KB
13.txt AC 49 ms 2176 KB
14.txt AC 33 ms 1920 KB
15.txt AC 53 ms 2304 KB
16.txt AC 22 ms 1152 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB