結果

問題 No.3558 Dominoes, Black and White
コンテスト
ユーザー GOTKAKO
提出日時 2026-05-29 21:20:48
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,224 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,397 ms
コンパイル使用メモリ 217,392 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-05-29 21:20:56
合計ジャッジ時間 5,273 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 10 % AC * 19 WA * 11
満点 90 % AC * 23 WA * 66
合計 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;
      |                       ^

ソースコード

diff #
raw source code

#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;
            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;
}
0