LeetCode Weekly Contest 166
問題文
省略
省略
C++に変換後のコードはこちら
#define main dummy_main
{}
#undef main
int x, y, xy;
int arr[3][3];
int dx[5] = {0, -1, 1, 0, 0};
int dy[5] = {0, 0, 0, -1, 1};
class Solution {
public:
int minFlips(vector<vector<int>>& mat) {
int i, j, si, sj, d, cnt;
int res = int_inf;
x = mat.size();
y = mat[0].size();
xy = x * y;
rep(mask,(1<<xy)){
cnt = 0;
rep(i,x) rep(j,y) arr[i][j] = mat[i][j];
rep(i,x) rep(j,y) if(mask & (1<<(i*y+j))){
cnt++;
rep(d,5){
si = i + dx[d];
sj = j + dy[d];
if(0 <= si < x && 0 <= sj < y) arr[si][sj] ^= 1;
}
}
rep(i,x) rep(j,y) if(arr[i][j]) break_break_continue;
res <?= cnt;
}
if(res==int_inf) res = -1;
return res;
}
};
Current time: 2024年04月26日11時21分33秒
Last modified: 2019年12月14日23時02分35秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る
Logged in as: unknown user (not login)