anonymous No title
C++
#include<bits/stdc++.h>
using namespace std;

vector<int> uselist[4][4];
bool piece[17];
int field[5][4];
int clist[10][4][2];
stack<int> putp;
stack<int> putx;
stack<int> puty;
vector<int> binex(int a){
    vector<int> ret = {0,0,0,0};
    int cnt = 0;
    while(a>0){
        ret[cnt]=a%2;
        a/=2;
        cnt++;
    }
    return ret;
}
bool check(vector<int> cclist){
    for(int i1 = cclist.size() - 1;i1 >= 0;i1--){
        int now = cclist[i1];
        int tmp[4] = {0,0,0,0};
        for(int i = 0;i<4;i++){
            if(field[clist[now][i][0]][clist[now][i][1]]==-1){
                for(int j = 0;j<4;j++){
                    tmp[j] = 5;
                }
                break;
            }
            vector<int> tmpp = binex(field[clist[now][i][0]][clist[now][i][1]]);
            for(int j = 0;j<4;j++) tmp[j]+=tmpp[j];
        }
        for(int i = 0;i<4;i++) if(tmp[i]==0 || tmp[i]==4) return true;
    }

    return false;
}
void putpiece(int y,int x,int piecenum){
    putx.push(x);
    puty.push(y);
    putp.push(piecenum);
    field[y][x] = piecenum;
    piece[piecenum] = false;
}
void deletepiece(){
    piece[putp.top()] = true;
    field[puty.top()][putx.top()] = -1;
    putx.pop();
    puty.pop();
    putp.pop();
}
int iswin(int nowhave,int nowdepth){
    if(nowdepth == 0){
        return -1;//0だった
    }
    bool drawflag = false;
    for(int i1 = 0;i1 < 4;i1++){
        for(int i2 = 0;i2 < 4;i2++){
            if(field[i1][i2] == -1){
                deletepiece();
                putpiece(i1,i2,nowhave);
            }else continue;
            if(check(uselist[i1][i2])){
                return 1;
            }
            for(int i3 = 0;i3<16;i3++){
                if(!piece[i3])continue;
                for(int i4 = 0;i4<4;i4++){
                    for(int i5 = 0;i5<4;i5++){
                        if(field[i4][i5] == -1){
                            putpiece(i4,i5,i3);
                        }else continue;
                        if(check(uselist[i4][i5])){
                            goto endloop1;
                        }
                        for(int i6 = 0;i6<16;i6++){
                            if(!piece[i6])continue;
                            putpiece(4,3,16);
                            int willwin = iswin(i6,nowdepth-1);
                            if(willwin == -1){
                                deletepiece();
                                goto endloop1;
                            }else if(willwin == 1){
                                deletepiece();
                            /*}else if(willwin == 0){
                                drawflag = true;
                                deletepiece();*/
                            }
                        }
                        deletepiece();
                    }
                }
                /*if(drawflag){
                    return 0;
                }else{*/
                    return 1;
                //}
                endloop1:;
                deletepiece();
            }
            
        }
    }
    /*if(drawflag){
        return 0;
    }else{*/
        return -1;
    //}
}
int main(){
    for(int i1 = 0;i1 < 4;i1++){
        for(int i2 = 0;i2 < 4;i2++){
            clist[i1][i2][0] = i1;
            clist[i1][i2][1] = i2;
            uselist[i1][i2].push_back(i1);
        }
    }
    for(int i1 = 0;i1 < 4;i1++){
         for(int i2 = 0;i2 < 4;i2++){
            clist[i1 + 4][i2][0] = i2;
            clist[i1 + 4][i2][1] = i1;
            uselist[i2][i1].push_back(i1 + 4);
        }
    }
    for(int i2 = 0;i2 < 4;i2++){
        clist[8][i2][0] = i2;
        clist[8][i2][1] = i2;
        clist[9][i2][0] = i2;
        clist[9][i2][1] = 3 - i2;
        uselist[i2][i2].push_back(8);
        uselist[i2][3 - i2].push_back(9);
    }
    for(int i = 0;i<16;i++){
        piece[i] = true;
    }
    for(int i1 = 0;i1 < 4;i1++){
        for(int i2 = 0;i2 < 4;i2++){
            cin >> field[i1][i2];
            piece[field[i1][i2]] == false;
        }
    }
    int youhave;
    int depth;
    cin >> youhave >> depth;
    putpiece(4,3,16);
    int iwillwin = iswin(youhave,depth);
    if(iwillwin == 1){
        cout << "win" << endl;
        while(!putx.empty()){
            cout << puty.top() << putx.top() << endl;
            cout << putp.top() << endl;
            putx.pop();
            puty.pop();
            putp.pop();
        }
    }else if(iwillwin == 0){
        cout << "draw" << endl;
    }else{
        cout << "lose" << endl;
        while(!putx.empty()){
            cout << puty.top() << putx.top() << endl;
            cout << putp.top() << endl;
            putx.pop();
            puty.pop();
            putp.pop();
        }
    }
    return 0;
}
anonymous No title
C++
#include <iostream>
#include <vector>
#include <set>
using namespace std;
// 今のfieldでputplaceにnowpieceを置いたときに勝ちかどうか
bool iswinvec(std::vector<int> a){
    if(a[0]==-1) return false;
    for(int i = 0;i<4;i++) if(a[i]==4 || a[i]==0) return true;
    return false;
}
std::vector<int> binex(int a){
    std::vector<int> ret = {0,0,0,0};
    int cnt = 0;
    while(a>0){
        ret[cnt]=a%2;
        a/=2;
        cnt++;
    }
    return ret;
}
bool iswin(std::vector<std::vector<int>> field,std::pair<int,int> putplace,int nowpiece){
    field[putplace.first][putplace.second]=nowpiece;
    for(int i = 0;i<4;i++){
        std::vector<int> tmp = {0,0,0,0};
        for(int j = 0;j<4;j++){
            if(field[i][j]<0){
                tmp = {-1,0,0,0};
                break;
            }
            std::vector<int> binextmp = binex(field[i][j]);
            for(int k = 0;k<4;k++){
                tmp[k]+=binextmp[k];
            }
        }
        if(iswinvec(tmp)) return true;
    }
    for(int i = 0;i<4;i++){
        std::vector<int> tmp = {0,0,0,0};
        for(int j = 0;j<4;j++){
            if(field[j][i]<0){
                tmp = {-1,0,0,0};
                break;
            }
            std::vector<int> binextmp = binex(field[j][i]);
            for(int k = 0;k<4;k++){
                tmp[k]+=binextmp[k];
            }
        }
        if(iswinvec(tmp)) return true;
    }
    for(int i = 0;i<1;i++){
        std::vector<int> tmp = {0,0,0,0};
        for(int j = 0;j<4;j++){
            if(field[j][j]<0){
                tmp = {-1,0,0,0};
                break;
            }
            std::vector<int> binextmp = binex(field[j][j]);
            for(int k = 0;k<4;k++){
                tmp[k]+=binextmp[k];
            }
        }
        if(iswinvec(tmp)) return true;
    }
    for(int i = 0;i<1;i++){
        std::vector<int> tmp = {0,0,0,0};
        for(int j = 0;j<4;j++){
            if(field[3-j][j]<0){
                tmp = {-1,0,0,0};
                break;
            }
            std::vector<int> binextmp = binex(field[3-j][j]);
            for(int k = 0;k<4;k++){
                tmp[k]+=binextmp[k];
            }
        }
        if(iswinvec(tmp))  return true;
    }
    return false;
}
std::vector<std::vector<int>> put(std::vector<std::vector<int>> field,std::pair<int,int> putplace,int nowpiece){
    field[putplace.first][putplace.second]=nowpiece;
    return field;
}
std::set<int> erase(std::set<int> remainpiece,int piece){
    remainpiece.erase(piece);
    return remainpiece;
}
std::vector<int> solve(std::vector<std::vector<int>> field,std::set<int> remainpiece,int nowpiece,int depth){
    //今おけるところを調べている
    std::vector<std::pair<int,int>> canput;
    for(int i=0;i<4;i++) for(int j=0;j<4;j++) if(field[i][j]<0) canput.push_back(std::make_pair(i,j));
    //今の一手で勝てるかどうかを調べてる
    for(int i=0;i<canput.size();i++){
        if(iswin(field,canput[i],nowpiece)){
            std::vector<int> ret = {1,canput[i].first,canput[i].second};
            //cout << nowpiece << endl;
            return ret;
        }
    }
    if(depth==1){
        std::vector<int> ret = {0,-1,-1};
        return ret;
    }
    std::vector<int> ret = {-1,-1,-1};
    int sign = -1;
    for(int i=0;i<canput.size();i++){
        for(auto itr = remainpiece.begin();itr!=remainpiece.end();itr++){
            std::vector<int> tmptmpret = solve(put(field,canput[i],nowpiece),erase(remainpiece,*itr),*itr,depth-1);
            tmptmpret[0]*=(-1);
            if(tmptmpret[0]==1){
                ret[0]=1;
                ret[1]=canput[i].first;
                ret[2]=canput[i].second;
                ret.push_back(*itr);
                //cout << ret[1] << " " << ret[2] << endl;
                return ret;
            };
            sign = max(tmptmpret[0],sign);
        }
        if(sign>ret[0]) ret[0] = sign;
        //if(ret[0]==1) return ret;
    }
    return ret;
}
int main(){
    std::vector<std::vector<int>> field;
   for(int i = 0;i<4;i++) field.push_back({});
    for(int i = 0;i<4;i++) for(int j = 0;j<4;j++) field[i].push_back(-1);
    for(int i = 0;i<4;i++) for(int j = 0;j<4;j++) std::cin >> field[i][j];
    int nowpiece,depth;
    std::cin >> nowpiece;
    std::cin >> depth;
    std::set<int> remainpiece;
    for(int i = 0;i<16;i++) remainpiece.insert(i);
    for(int i = 0;i<4;i++) for(int j = 0;j<4;j++){
        if(field[i][j]!=-1) remainpiece.erase(field[i][j]);
    }
    remainpiece.erase(nowpiece);
    std::vector<int> result = solve(field,remainpiece,nowpiece,depth);
    std::cout << result[0] << " " << result[1] << " " << result[2] << std::endl;
    if(result.size()==4) cout << result[3] << endl;
}
anonymous No title
C++
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)

typedef long long ll;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;

int T[123][123] = {};
ll Cost[123][123] =  {};
int H,W,C;

bool IsIn(int x,int y){
    return 0<=x&&x<H&&0<=y&&y<W;
}
int main() {
    cin>>H>>W>>C;
    rep(i,H)rep(j,W){
        cin>>T[i][j];
        Cost[i][j] = INF;
    }
    Cost[0][0] = 0;
    queue<pair<int,int>> Q;
    Q.push({0,0});
    while(!Q.empty()){
        auto p =  Q.front();
        int x = p.first;
        int y = p.second;
        Q.pop();
        rep(i,2){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!IsIn(nx,ny))continue;
            if(T[nx][ny]==1){
                //chmin(Cost[nx][ny], Cost[x][y] + C);
                Cost[nx][ny] = min(Cost[nx][ny], Cost[x][y] + C);
            }
            else{
                Cost[nx][ny] = min(Cost[nx][ny], Cost[x][y]);
                //chmin(Cost[nx][ny], Cost[x][y]);
            }
            Q.push({nx,ny});
        }
    }
    cout<<Cost[H-1][W-1]<<endl;
}
Retired K@PCK No title
C++
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================
monkukui No title
C++
50 149
45 47 8
36 44 2
27 34 10
47 9 9
9 45 1
4 9 5
29 24 4
28 3 6
10 7 1
9 33 2
29 25 1
35 20 1
47 4 10
49 24 5
16 35 1
39 23 9
7 26 1
45 33 1
19 43 8
11 25 4
17 26 1
23 18 8
28 18 9
24 31 1
40 1 6
17 20 9
42 5 10
39 28 4
10 40 5
9 22 2
4 33 1
17 7 1
6 27 1
24 49 5
40 2 6
48 28 6
4 33 1
23 28 1
37 25 5
12 23 9
5 44 6
45 22 3
18 48 1
16 20 1
19 1 8
39 14 10
37 49 8
33 47 7
24 25 2
39 32 2
43 1 1
36 8 1
44 8 7
37 39 2
23 3 6
44 36 2
6 27 1
32 3 2
32 14 6
11 30 6
14 32 6
22 9 2
25 31 1
9 15 10
48 30 5
29 38 9
11 31 9
4 22 8
17 26 1
38 39 1
47 22 2
21 14 6
1 40 6
38 23 8
12 7 8
1 43 1
30 18 7
1 19 8
36 6 9
44 46 3
31 25 1
38 11 9
47 22 2
48 23 6
37 14 6
48 18 1
48 30 5
17 10 3
13 42 3
48 28 6
46 4 8
32 38 4
4 44 4
10 40 5
25 38 6
8 27 6
23 32 10
28 38 2
16 50 9
1 2 5
39 25 7
19 35 8
7 17 1
36 8 1
44 46 3
4 44 4
8 18 10
29 11 2
18 27 9
18 27 9
29 37 10
3 38 9
35 19 8
33 44 8
38 28 2
37 31 6
26 12 4
17 35 10
46 5 1
28 32 6
31 49 8
45 9 1
4 36 6
4 8 10
24 31 1
38 39 1
26 10 6
41 21 10
39 32 2
46 5 1
39 37 2
3 12 6
26 12 4
8 6 6
11 29 2
31 29 2
37 24 7
50 16 9
23 28 1
22 33 4
35 20 1
32 37 4
39 3 7
33 45 1
3 32 2
40 19 9
25 37 5
45 4 2
37 38 4
monkukui No title
C++
50 100
47 3 6
42 36 9
45 19 10
46 15 5
13 41 2
7 49 9
8 14 9
3 42 3
11 12 5
15 30 2
24 11 4
33 46 10
8 43 7
12 35 4
22 27 10
10 18 2
11 39 6
45 16 1
32 48 4
39 16 6
25 44 7
48 28 4
29 49 3
15 12 5
1 31 3
37 24 8
27 9 2
15 27 6
16 15 9
15 35 5
7 17 8
11 19 4
10 32 10
28 38 8
32 3 4
33 9 8
5 23 7
48 39 7
30 6 5
23 18 7
46 9 2
38 49 8
41 27 9
22 38 3
47 2 4
23 21 6
16 43 8
32 23 2
39 28 10
33 40 4
2 17 2
13 26 3
25 13 10
4 16 1
3 20 4
41 40 3
40 10 10
37 3 10
20 34 3
33 17 7
24 20 6
32 14 9
37 31 10
14 33 5
49 16 7
31 34 8
38 18 9
7 36 2
23 43 9
3 49 4
50 38 10
40 20 8
2 37 1
43 42 7
11 25 7
3 1 4
43 29 4
1 48 7
10 13 6
8 12 8
24 4 3
18 42 5
35 46 5
45 30 10
27 21 4
29 39 8
33 50 7
17 15 9
19 34 3
8 32 3
38 8 8
18 43 4
5 24 6
31 16 1
49 9 5
13 47 6
42 46 10
26 49 7
26 22 6
12 1 5
monkukui No title
C++
50 150
42 43 2
37 49 8
41 26 10
10 13 1
9 33 6
19 4 6
43 23 8
49 3 10
8 38 4
16 10 7
34 24 4
43 18 5
28 6 8
23 32 9
30 15 6
22 38 10
49 9 3
33 40 1
18 25 2
11 39 7
17 15 10
25 16 2
16 19 1
38 24 9
1 31 9
16 15 5
9 7 1
28 39 2
10 36 7
10 40 9
48 46 10
9 32 4
7 17 1
46 24 8
43 2 10
28 38 5
4 24 4
34 20 3
26 30 2
13 47 8
50 7 2
20 24 3
16 49 5
33 14 7
3 2 6
14 44 8
38 41 10
35 46 3
47 23 3
48 31 6
37 2 9
46 9 5
9 28 4
40 38 8
47 3 3
36 42 6
14 8 8
20 3 5
13 41 2
12 15 8
26 13 3
10 32 5
26 49 6
18 10 7
29 39 1
29 48 8
12 28 5
5 24 2
15 46 1
50 38 7
40 20 4
13 25 5
47 2 9
34 21 8
8 43 4
3 1 4
16 39 4
48 1 6
8 12 6
46 42 7
44 25 4
43 12 3
45 19 3
26 22 1
32 14 9
45 16 10
47 30 7
11 12 7
31 13 4
49 29 2
6 25 2
32 48 10
3 44 4
11 25 7
26 33 8
9 27 10
21 23 1
27 41 6
15 35 10
12 1 5
26 39 4
17 33 10
20 8 4
9 20 8
40 41 6
6 26 10
42 9 4
11 19 7
16 31 4
16 43 2
29 43 2
42 3 5
18 38 1
50 33 4
33 28 1
45 30 7
13 49 9
32 16 2
7 36 10
28 48 9
37 31 7
10 23 9
5 23 3
4 16 6
22 27 10
48 39 5
24 11 10
27 19 3
46 33 2
49 7 6
37 46 8
17 2 3
19 12 9
8 32 3
35 12 5
46 29 3
37 24 7
15 27 10
21 27 2
34 19 10
18 23 9
34 31 2
3 37 5
34 46 10
32 3 4
18 42 9
36 24 8
6 30 1
49 38 7
5 37 6
monkukui No title
C++
50 96
23 3 10
39 38 1
49 24 10
27 18 10
20 16 1
46 5 1
10 7 3a
33 4 1
10 40 10
17 26 3
11 29 4
37 39 4
8 36 1
12 26 8
37 25 10
9 45 1
12 26 8
22 33 7
36 44 5
22 47 4
28 48 10
31 29 3
32 39 4
42 13 6
1 40 10
38 28 5
9 22 5
48 18 1
18 48 1
26 17 3
8 6 10
11 29 4
33 9 4
28 48 10
3 32 4
9 22 5
5 46 1
25 31 2
42 5 10
31 24 1
9 15 10
46 44 5
39 28 7
31 25 2
40 1 10
25 29 1
41 21 10
25 38 10
48 30 10
38 37 7
3 12 10
21 14 10
32 14 10
4 44 7
4 44 7
28 38 5
40 10 10
4 9 9
24 49 10
45 22 6
29 24 7
50 16 10
33 45 1
35 16 1
35 20 1
45 33 1
47 22 4
6 27 2
34 27 10
3 32 4
46 44 5
24 31 1
1 43 2
1 2 10
25 11 7
43 1 2
32 37 8
19 1 10
10 17 6
17 7 2
33 4 1
23 28 2
38 39 1
32 39 4
37 25 10
32 38 8
37 39 4
35 19 10
25 24 5
6 27 2
7 26 3
28 23 2
4 45 4
20 35 1
45 9 1
14 32 10
monkukui No title
C++
50 96
23 3 10
39 38 1
49 24 10
27 18 10
20 16 1
46 5 1
10 7 3
33 4 1
10 40 10
17 26 3
11 29 4
37 39 4
8 36 1
12 26 8
37 25 10
9 45 1
12 26 8
22 33 7
36 44 5
22 47 4
28 48 10
31 29 3
32 39 4
42 13 6
1 40 10
38 28 5
9 22 5
48 18 1
18 48 1
26 17 3
8 6 10
11 29 4
33 9 4
28 48 10
3 32 4
9 22 5
5 46 1
25 31 2
42 5 10
31 24 1
9 15 10
46 44 5
39 28 7
31 25 2
40 1 10
25 29 1
41 21 10
25 38 10
48 30 10
38 37 7
3 12 10
21 14 10
32 14 10
4 44 7
4 44 7
28 38 5
40 10 10
4 9 9
24 49 10
45 22 6
29 24 7
50 16 10
33 45 1
35 16 1
35 20 1
45 33 1
47 22 4
6 27 2
34 27 10
3 32 4
46 44 5
24 31 1
1 43 2
1 2 10
25 11 7
43 1 2
32 37 8
19 1 10
10 17 6
17 7 2
33 4 1
23 28 2
38 39 1
32 39 4
37 25 10
32 38 8
37 39 4
35 19 10
25 24 5
6 27 2
7 26 3
28 23 2
4 45 4
20 35 1
45 9 1
14 32 10
monkukui No title
C++
10 47
4 2 6
2 7 2
10 9 3
2 10 1
8 9 2
8 3 4
4 8 1
2 9 4
5 10 9
7 10 1
8 6 1
4 9 1
6 4 2
10 7 1
10 1 1
5 7 9
6 9 4
2 10 1
3 4 4
8 5 1
6 7 10
7 3 1
5 3 9
7 9 3
4 1 10
2 1 1
8 4 1
5 4 1
9 7 3
3 1 8
10 3 2
8 6 1
6 5 3
4 5 1
2 3 7
4 10 5
3 6 6
9 3 4
7 3 1
8 10 8
9 4 1
4 7 4
9 5 1
8 7 6
1 9 6
5 2 9
7 1 2
Don't you submit code?
Submit