AtCoder Beginner Contest 025

Submission #1674071

Source codeソースコード

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;

int b[2][3], c[3][2];
ll sum = 0;

ll eval(std::vector<int> v){
  int ret = 0;
  rep(i,3){
    rep(j,3){
      if(i != 2 && (v[3*i+j] == v[3*(i+1)+j]))  ret += b[i][j];
      if(j != 2 && (v[3*i+j] == v[3*i+j+1])) ret += c[i][j];
    }
  }
  return ret;
}

int dfs(int depth, vector<int> v){
  if(depth == 9) return eval(v);
  int ret = (depth % 2 == 0 ? -1 : sum+1);

  rep(i, 9){
    if(v[i] != 0) continue;
    vector<int> v2(v);
    v2[i] = (depth % 2 == 0 ? 1 : -1);
    int tmp = dfs(depth+1, v2);
    if(depth % 2 == 0) ret = max(ret, tmp);
    else ret = min(ret, tmp);
  }

  return ret;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  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];}

  vector<int> buff(9, 0);
  int  ans = dfs(0, buff);
  cout << ans << endl << (sum - ans) << endl;

  return 0;
}

Submission

Task問題 C - 双子と○×ゲーム
User nameユーザ名 madorin
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 3433 Byte
File nameファイル名
Exec time実行時間 117 ms
Memory usageメモリ使用量 256 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample-01.txt,sample-02.txt
All 100 / 100 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample-01.txt AC 114 ms 256 KB
sample-02.txt AC 115 ms 256 KB
test-01.txt AC 117 ms 256 KB
test-02.txt AC 114 ms 256 KB
test-03.txt AC 116 ms 256 KB
test-04.txt AC 114 ms 256 KB
test-05.txt AC 113 ms 256 KB
test-06.txt AC 116 ms 256 KB
test-07.txt AC 115 ms 256 KB
test-08.txt AC 113 ms 256 KB
test-09.txt AC 116 ms 256 KB
test-10.txt AC 113 ms 256 KB
test-11.txt AC 113 ms 256 KB
test-12.txt AC 115 ms 256 KB
test-13.txt AC 115 ms 256 KB
test-14.txt AC 113 ms 256 KB
test-15.txt AC 114 ms 256 KB
test-16.txt AC 115 ms 256 KB
test-17.txt AC 112 ms 256 KB
test-18.txt AC 114 ms 256 KB
test-19.txt AC 116 ms 256 KB
test-20.txt AC 115 ms 256 KB