結果
| 問題 | No.3558 Dominoes, Black and White |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-29 21:25:45 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,257 bytes |
| 記録 | |
| コンパイル時間 | 1,283 ms |
| コンパイル使用メモリ | 220,056 KB |
| 実行使用メモリ | 7,976 KB |
| 最終ジャッジ日時 | 2026-05-29 21:25:52 |
| 合計ジャッジ時間 | 4,065 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 10 % | AC * 12 WA * 18 |
| 満点 | 90 % | AC * 16 WA * 73 |
| 合計 | 0 点 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:29:32: warning: 'w' may be used uninitialized [-Wmaybe-uninitialized]
29 | long long w = white-w;
| ~~~~~^~
main.cpp:29:23: note: 'w' was declared here
29 | long long w = white-w;
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
stack<pair<long long,long long>> st;
long long answer = 0;
for(int x=0; x<N; x++){
string s; cin >> s;
long long white = 0,black = 2*N;
for(int i=0; i<2*N; i++) if(s.at(i) == '.') answer += i-white,white++;
black -= white;
if(black > N){
long long b = black-N;
answer += b*(b-1)/2;
while(st.size() && st.top().second > 0 && b){
auto &[x2,w] = st.top();
long long use = min(b,w);
answer += use*(x-x2+1);
w -= use,b -= use;
if(w == 0) st.pop();
}
if(b) st.push({x,-b});
}
else if(white > N){
long long w = white-w;
answer += w*(w-1)/2;
while(st.size() && st.top().second < 0 && w){
auto &[x2,b] = st.top();
long long use = min(-b,w);
answer += use*(x-x2+1);
w -= use,b += use;
if(b == 0) st.pop();
}
if(w) st.push({x,w});
}
}
cout << answer << endl;
}