Submission #3043135


Source Code Expand

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000009LL
#define EPS 1e-8

int b[ 2 ][ 3 ];
int c[ 3 ][ 2 ];

int calcScore( int tbl[ 3 ][ 3 ] )
{
	int score = 0;
	REP( i, 2 )
	{
		REP( j, 3 )
		{
			if( tbl[ i ][ j ] != -1 && tbl[ i + 1 ][ j ] != -1 )
			{
				if( tbl[ i ][ j ] == tbl[ i + 1 ][ j ] )
				{
					score += b[ i ][ j ];
				}
				else
				{
					score -= b[ i ][ j ];
				}
			}
		}
	}
	REP( i, 3 )
	{
		REP( j, 2 )
		{
			if( tbl[ i ][ j ] != -1 && tbl[ i ][ j + 1 ] != -1 )
			{
				if( tbl[ i ][ j ] == tbl[ i ][ j + 1 ] )
				{
					score += c[ i ][ j ];
				}
				else
				{
					score -= c[ i ][ j ];
				}
			}
		}
	}
	return score;
}

int dfs( int tbl[ 3 ][ 3 ], int turn )
{
	if( turn == 9 ) return calcScore( tbl );
	else
	{
		bool isMale = turn % 2 == 0;
		int bestScore = isMale ? - ( 1 << 29 ) : ( 1 << 29 );
		REP( i, 3 )
		{
			REP( j, 3 )
			{
				if( tbl[ i ][ j ] == -1 )
				{
					tbl[ i ][ j ] = isMale ? 1 : 0;
					int score = dfs( tbl, turn + 1 );
					if( isMale )
					{
						if( score > bestScore ) bestScore = score;
					}
					else
					{
						if( score < bestScore ) bestScore = score;
					}
					tbl[ i ][ j ] = -1;
				}
			}
		}
		return bestScore;
	}
}

int main()
{
	int sum = 0;
	REP( i, 2 ) REP( j, 3 ) { cin >> b[ i ][ j ]; sum += b[ i ][ j ]; }
	REP( i, 3 ) REP( j, 2 ) { cin >> c[ i ][ j ]; sum += c[ i ][ j ]; }
	int tbl[ 3 ][ 3 ];
	REP( i, 3 ) REP( j, 3 ) tbl[ i ][ j ] = -1;
	int score = dfs( tbl, 0 );
	int scoreM = ( score + sum ) / 2;
	int scoreF = sum - scoreM;
	cout << scoreM << endl;
	cout << scoreF << endl;
	return 0;
}

Submission Info

Submission Time
Task C - 双子と○×ゲーム
User keitanxkeitan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2844 Byte
Status AC
Exec Time 29 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 29 ms 256 KB
sample-02.txt AC 29 ms 256 KB
test-01.txt AC 29 ms 256 KB
test-02.txt AC 29 ms 256 KB
test-03.txt AC 29 ms 256 KB
test-04.txt AC 29 ms 256 KB
test-05.txt AC 29 ms 256 KB
test-06.txt AC 29 ms 256 KB
test-07.txt AC 29 ms 256 KB
test-08.txt AC 29 ms 256 KB
test-09.txt AC 29 ms 256 KB
test-10.txt AC 29 ms 256 KB
test-11.txt AC 29 ms 256 KB
test-12.txt AC 29 ms 256 KB
test-13.txt AC 29 ms 256 KB
test-14.txt AC 29 ms 256 KB
test-15.txt AC 29 ms 256 KB
test-16.txt AC 29 ms 256 KB
test-17.txt AC 29 ms 256 KB
test-18.txt AC 29 ms 256 KB
test-19.txt AC 29 ms 256 KB
test-20.txt AC 29 ms 256 KB