Submission #2066056
Source Code Expand
import Data.Map.Strict (Map, (!))
import qualified Data.Map.Strict as M
data Check = O | X deriving (Eq, Show)
main :: IO ()
main = do
[b11,b12,b13] <- map read . words <$> getLine
[b21,b22,b23] <- map read . words <$> getLine
[c11,c12] <- map read . words <$> getLine
[c21,c22] <- map read . words <$> getLine
[c31,c32] <- map read . words <$> getLine
let
ps = M.fromList [(((1,1),(2,1)),b11),(((1,2),(2,2)),b12),(((1,3),(2,3)),b13),
(((2,1),(3,1)),b21),(((2,2),(3,2)),b22),(((2,3),(3,3)),b23),
(((1,1),(1,2)),c11),(((1,2),(1,3)),c12),
(((2,1),(2,2)),c21),(((2,2),(2,3)),c22),
(((3,1),(3,2)),c31),(((3,2),(3,3)),c32)]
psum = sum (M.elems ps)
board = M.empty
chokudai = gsearch board 0 ps
print chokudai
print (psum - chokudai)
gsearch :: Map (Int,Int) Check -> Int -> Map ((Int,Int),(Int,Int)) Int -> Int
gsearch board 9 ps = score board ps
gsearch board t ps
| even t = maximum [gsearch (M.insert (i,j) O board) (t+1) ps | i<-[1..3], j<-[1..3], M.notMember (i,j) board]
| otherwise = minimum [gsearch (M.insert (i,j) X board) (t+1) ps | i<-[1..3], j<-[1..3], M.notMember (i,j) board]
score :: Map (Int,Int) Check -> Map ((Int,Int),(Int,Int)) Int -> Int
score board ps = sum [south i j + east i j | i<-[1..3], j<-[1..3]]
where
south i j = if i<3 && board!(i,j) == board!(i+1,j) then ps!((i,j),(i+1,j)) else 0
east i j = if j<3 && board!(i,j) == board!(i,j+1) then ps!((i,j),(i,j+1)) else 0
Submission Info
Submission Time |
|
Task |
C - 双子と○×ゲーム |
User |
aimy |
Language |
Haskell (GHC 7.10.3) |
Score |
100 |
Code Size |
1562 Byte |
Status |
AC |
Exec Time |
995 ms |
Memory |
1276 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
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 |
993 ms |
1276 KB |
sample-02.txt |
AC |
994 ms |
1276 KB |
test-01.txt |
AC |
993 ms |
1276 KB |
test-02.txt |
AC |
993 ms |
1276 KB |
test-03.txt |
AC |
994 ms |
1276 KB |
test-04.txt |
AC |
993 ms |
1276 KB |
test-05.txt |
AC |
994 ms |
1276 KB |
test-06.txt |
AC |
994 ms |
1276 KB |
test-07.txt |
AC |
994 ms |
1276 KB |
test-08.txt |
AC |
994 ms |
1276 KB |
test-09.txt |
AC |
993 ms |
1276 KB |
test-10.txt |
AC |
994 ms |
1276 KB |
test-11.txt |
AC |
990 ms |
1148 KB |
test-12.txt |
AC |
993 ms |
1276 KB |
test-13.txt |
AC |
995 ms |
1276 KB |
test-14.txt |
AC |
995 ms |
1276 KB |
test-15.txt |
AC |
994 ms |
1276 KB |
test-16.txt |
AC |
993 ms |
1276 KB |
test-17.txt |
AC |
993 ms |
1276 KB |
test-18.txt |
AC |
994 ms |
1276 KB |
test-19.txt |
AC |
995 ms |
1276 KB |
test-20.txt |
AC |
993 ms |
1276 KB |