Submission #3974841


Source Code Expand

// だーれだ?
//qqqqqqHHMqqqqqHf!(:;jHmmkf``(:;jkqqqqqqqqqmMH#HMqqK_````````````````(kqqqqqqHMMM
//qqqqqqHHmqqqqH=` :;;jkqH=?~..;;jqqqqqqqqqmM#HM#MHH!```` ```````..-``dqWbWkRqHMMM
//qqqqqqMHmqqqK!``.;;;dqH: ```.?TUqqHmqqqqmHHHM4Mqkt..```` ..JgHHW@P`.HHkqHHHqM#NN
//qqqqqmHMmqHTYWHgHmmgHR...``` :;Jkq9qqqqqgMH#1dHk$...-gW@HY"=!``dH! dHNmqqqqmM###
//qqqqqqgMmH[````` ?dHMMMHHHHHJ<;JkK>XqqqmMH#<+Hb%.WYYTHppf-````.gt`.HHMmmqqqmM###
//qqkqqqm@H?S,```` Jpbbpp:```` :!dK<;JkqqMMY(;dW^````.ppbpf!```.Y<`.HHHMgmqqqmH###
//qqqqqqqqD`` ````(ppbppW````` ~.f`:;jkqM#^.;jf!````.Wppbpf````````(HH#HmmqqmH#NN#
//qqqqqqqkP``````.fpbpbpf``` ` `.``~:;WHY``(+=``````Jppbpf\```` ``.MH#HHgqqqmHNNNN
//qqqqqqqk]```` `,fpbbpf>```` `` ``_:<? ``.?!``` `` Wpppp%``` ``` dHH##HmmqqmH####
//qqqqqqqk]``````,fpbppt``` `` `` `_~````` `` `` ```WppW=``` ````.HHHHMHmmqqmM####
//qqqqqqqk$`` ````4ppfY```` `` `` `- `` `` `` ``` ``(T=`````` ``.MH##HMMmmqqmM##HH
//qqqqqqHqP``` ````?7!```` `` `` ``` `` ` ` ``  ````````` ` ````.MHH#HgMmqmqmHHHHH
//qqqkqqmkR```` `        `` ` `` ` ` ` ``` ` ``` `   ......_. ```dH#HHgMqqgqqmH#HH
//NqqqqqHqR```  _ ........_` `` ``` ``` ````` ``` ............```,HHHHmqqqHqqmMH##
//MmqqqqHqR```  _........_ `` `` ``` `` `  `` ` ` `  `__     ` ``,HHHMmmqqMHmmMHH#
//HMqqqqXkH `````````````` ` `` `  `` `` `` `` `` ```` ````` ````.HHHMmMHm@HHqmMHH
//HHHmqqfHk;``` `  ` `` ` ` `` ``` ` ` ``` `` `` `` ````  `..```.HHHHMMHMg@HHHHHMH
//HHMmmqMHkP<.`` ``` ` ` ``` `` ``` ``` ` `` `` `` `  ````  ```.MH##HM#HMg@@@@H@HH
//##HNmqR`jW<<_ ``` ````` `` ` ` ``` `` `` `` `` ````  ````` .dHH##H#HHHMHH@@H@@@@
//HH##NqH..X2:<<-.`` ` `` ``` ``` ` `` `` `` ` `` ` ``` ` .gMHHH#H#HHH#HM@@H@@H@@H
//-WHHHNH[ =v._:::<-. ` `` ` ``  ```````.`` `````````     .MHH###H#MHHHHH@H@H@@HH@
//` 7MHHMH.l==.  ~:::::<_-.. ````` ``````` ``  ...uX;     `,MHHHH#M@@MM@@@@@@H@@@@
//  . TMHHbZl=1.   _~::::::(<::<:<___-___:<<:::::jX3=. ` ` `,MMHM@@@@Mg@@@@@@@@@H@
//
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define IN(i,a,b) (a)<=(i) && (i)<(b)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << " = " << (x) << endl;
const int inf=1001001001; const long long INF=1001001001001001001;
using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int to, from, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};

int b[2][3], c[3][2], ans, mp[9], sum;

int dfs(int turn) {
  if (turn == 9) {
    int res = 0;
    rep(i, 0, 2) rep(j, 0, 3) {
      if (mp[3*i+j] == mp[3*(i+1)+j])
        res += b[i][j];
      if (mp[3*j+i] == mp[3*j+i+1])
        res += c[j][i];
    }
    return res;
  } else {
    int res = 0;
    rep(i, 0, 9) {
      if (mp[i] == -1) {
        mp[i] = turn % 2;
        int t = dfs(turn+1);
        mp[i] = -1;
        if (turn % 2 == 1) {
          t = sum - t;
        }
        res = max(res, t);
      }
    }
    if (turn % 2 == 0) 
      return res;
    else 
      return sum - res;
  }
}

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  rep(i, 0, 2) rep(j, 0, 3) {
    cin >> b[i][j];
    sum += b[i][j];
  }
  rep(i, 0, 3) rep(j, 0, 2) {
    cin >> c[i][j];
    sum += c[i][j];
  }
  int turn = 0;
  memset(mp, -1, sizeof(mp));
  ans = dfs(0);
  cout << ans << endl;
  cout << sum - ans << endl;
  return 0;
}

Submission Info

Submission Time
Task C - 双子と○×ゲーム
User kage
Language C++14 (GCC 5.4.1)
Score 100
Code Size 4590 Byte
Status AC
Exec Time 31 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample-01.txt, sample-02.txt
All sample-01.txt, sample-02.txt, test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
sample-01.txt AC 27 ms 256 KB
sample-02.txt AC 27 ms 256 KB
test-01.txt AC 27 ms 256 KB
test-02.txt AC 27 ms 256 KB
test-03.txt AC 27 ms 256 KB
test-04.txt AC 27 ms 256 KB
test-05.txt AC 27 ms 256 KB
test-06.txt AC 27 ms 256 KB
test-07.txt AC 27 ms 256 KB
test-08.txt AC 27 ms 256 KB
test-09.txt AC 31 ms 256 KB
test-10.txt AC 27 ms 256 KB
test-11.txt AC 27 ms 256 KB
test-12.txt AC 27 ms 256 KB
test-13.txt AC 27 ms 256 KB
test-14.txt AC 27 ms 256 KB
test-15.txt AC 27 ms 256 KB
test-16.txt AC 27 ms 256 KB
test-17.txt AC 27 ms 256 KB
test-18.txt AC 27 ms 256 KB
test-19.txt AC 27 ms 256 KB
test-20.txt AC 27 ms 256 KB