Codeforces 400(#234 Div2 only) A Inna and Choose Options
問題
それぞれ'O'か'X'が描かれた12枚のカードがある。
i番目のカードにはs[i]が描かれている。
二数a, bを選び、このカードを次のように並べる。
最初のb枚を取って一列に、
次のb枚を取ってその下の列に一列に並べる……
こうして12枚のカードをa行b列に並べた後、どこかの列に'X'が揃っていたら勝ちである。
勝ちになるa, bの組を全て出力せよ。
方針
テーブルか何かに並べるとわかりやすい。
ソースコード
int n; bool ok(string s, int h, int w){ int a[12][12]; rep(i, h) rep(j, w) a[i][j] = s[i * w + j] == 'X'; rep(i, w){ bool ok = 1; rep(j, h) if(!a[j][i]) ok = 0; if(ok) return 1; } return 0; } int main(){ cin >> n; while(n--){ string s; vi ans; cin >> s; for(int i = 1; i <= 12; i++) if(12 % i == 0){ if(ok(s, i, 12 / i)) ans.pb(i); } cout << ans.size(); rep(i, ans.size()) cout << " " << ans[i] << "x" << 12 / ans[i]; cout << endl; } return 0; }