結果

問題 No.3219 Ruler to Maximize
ユーザー kakel-san
提出日時 2025-08-01 22:00:43
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,624 bytes
コンパイル時間 8,549 ms
コンパイル使用メモリ 169,000 KB
実行使用メモリ 187,772 KB
最終ジャッジ日時 2025-08-01 22:00:56
合計ジャッジ時間 12,327 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (125 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        var w = 0;
        var b = 0;
        var ans = new char[n];
        for (var i = 0; i < n; ++i) if (a[i] == 0) ans[i] = 'W';
        var isw = true;
        for (var i = 12; i >= 0; --i)
        {
            var addor = 0;
            List<int> added;
            do
            {
                added = new List<int>();
                for (var j = 0; j < n; ++j)
                {
                    if (ans[j] == 0 && ((((a[j] >> i) & 1) != 0) || (a[j] & addor) != 0))
                    {
                        if (isw)
                        {
                            w |= a[j];
                            ans[j] = 'W';
                        }
                        else
                        {
                            b |= a[j];
                            ans[j] = 'B';
                        }
                        added.Add(a[j]);
                        addor |= a[j];
                    }
                }
            } while (added.Count > 0);
            if (w > 0) isw = false;
        }
        WriteLine(w * b);
        WriteLine(string.Concat(ans));
    }
}
0