結果

問題 No.387 ハンコ
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2018-03-03 23:57:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 3,693 ms / 5,000 ms
コード長 9,592 bytes
コンパイル時間 3,005 ms
コンパイル使用メモリ 114,172 KB
実行使用メモリ 56,788 KB
最終ジャッジ日時 2023-09-18 13:23:54
合計ジャッジ時間 24,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,693 ms
55,540 KB
testcase_01 AC 3,632 ms
55,468 KB
testcase_02 AC 1,208 ms
34,988 KB
testcase_03 AC 1,209 ms
33,052 KB
testcase_04 AC 258 ms
37,124 KB
testcase_05 AC 1,469 ms
56,324 KB
testcase_06 AC 2,444 ms
56,788 KB
testcase_07 AC 1,225 ms
40,192 KB
testcase_08 AC 1,243 ms
53,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
namespace Program {
    public class Solver {
        Random rnd = new Random(0);
        public void Solve() {
            var n = ri;
            var a = Enumerate(100000, x => new List<int>());
            for (int i = 0; i < n; i++)
                a[ri - 1].Add(i);
            var b = new BitSet(n);
            for (int i = 0; i < n; i++)
                if (ri == 1) b[i] = true;
            var ans = new BitSet(2 * n - 1);

            foreach (var v in a)
            {
                if (v.Count == 0) continue;
                var dp = new BitSet(2 * n - 1);
                foreach (var x in v) dp.ApplyOR(b, x);
                Debug.WriteLine(dp.Items.Select(x => x ? '1' : '0').AsString());
                ans.ApplyXOR(dp);
            }
            for (int i = 0; i < 2 * n - 1; i++)
                if (ans[i]) Console.WriteLine("ODD");
                else Console.WriteLine("EVEN");
        }
        const long INF = 1L << 60;
        static int[] dx = { -1, 0, 1, 0 };
        static int[] dy = { 0, 1, 0, -1 };

        int ri { get { return sc.Integer(); } }
        long rl { get { return sc.Long(); } }
        double rd { get { return sc.Double(); } }
        string rs { get { return sc.Scan(); } }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

        static T[] Enumerate<T>(int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f(i);
            return a;
        }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex {
    static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }

    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie);
    }

    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        try
        {
            solver.Solve();
            Console.Out.Flush();
        }
        catch { }
    }
}
#endregion
#region Ex
namespace Program.IO {
    using System.IO;
    using System.Text;
    using System.Globalization;

    public class Printer: StreamWriter {
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }

    public class StreamScanner {
        public StreamScanner(Stream stream) { str = stream; }

        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }

        private byte read() {
            if (isEof) return 0;
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }

        public char Char() {
            byte b = 0;
            do b = read(); while ((b < 33 || 126 < b) && !isEof);
            return (char)b;
        }
        public string Scan() {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine() {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
        public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
        public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}

#endregion
#region BitSet
public class BitSet {
    const int B = 64;
    static readonly ulong[] mask = new ulong[65];
    static readonly ulong[] revmask = new ulong[65];
    static readonly ulong[] cache = new ulong[1000000];
    static BitSet() {
        mask[0] = 0;
        for (int i = 0; i < 64; i++)
            mask[i + 1] = (mask[i] << 1) | 1ul;
        for (int i = 0; i < 65; i++)
            revmask[i] = ~mask[i];
    }
    static void align(ref int l1, int l2, ref int len, int m1) {
        if (l1 < 0) { l2 += Math.Abs(l1); len -= Math.Abs(l1); l1 = 0; }
        len = Math.Min(m1 - l1, len);
    }
    public int n;
    public ulong[] bits;
    public BitSet(int N) {
        n = N;
        bits = new ulong[n / B + 2];
    }
    public bool this[int index] {
        get { return (bits[index / B] >> index & 1) == 1; }
        set {
            if (value)
                bits[index / B] |= 1ul << index;
            else bits[index / B] &= ~(1ul << index);
        }
    }
    public bool[] Items {
        get {
            var ret = new bool[n];
            for (int i = 0; i < n; i++)
                ret[i] = this[i];
            return ret;
        }
    }

    /// <summary>
    /// this &amp;= Mask &lt;&lt; shift
    /// </summary>
    public void ApplyAND(BitSet Mask, int shift = 0) {
        ApplyAND(Mask, Math.Max(shift, 0), n, Math.Max(-shift, 0));
    }
    /// <summary>
    /// this[l1,l1+len) &amp;= mask[l2,l2+len)
    /// </summary>
    public void ApplyAND(BitSet Mask, int l1, int len, int l2 = 0) {
        align(ref l1, l2, ref len, n);
        align(ref l2, l1, ref len, Mask.n);

        int lx = l1 / B, ly = l1 % B, rx = (l1 + len) / B, ry = (l1 + len) % B;
        var dx = (l2 - l1) / B;
        var dy = (l2 - l1) % B;
        if (dy < 0) { dy += B; dx--; }
        var revdy = (B - dy) % B;
        cache[lx] = (lx + dx >= 0 ? Mask.bits[lx + dx] >> dy : 0) | (revdy == 0 ? 0 : Mask.bits[lx + dx + 1] << revdy);

        if (lx == rx) bits[lx] &= cache[lx] | ~(mask[ry] & revmask[ly]);
        else
        {
            if (revdy == 0) Buffer.BlockCopy(Mask.bits, (lx + dx + 1) * sizeof(ulong), cache, (lx + 1) * sizeof(ulong), (rx - lx) * sizeof(ulong));
            else
            {
                for (int i = lx + 1; i <= rx; i++)
                    cache[i] = Mask.bits[i + dx] >> dy | Mask.bits[i + dx + 1] << revdy;
            }
            bits[lx] &= cache[lx] | ~revmask[ly];
            for (int i = lx + 1; i < rx; i++)
                bits[i] &= cache[i];
            bits[rx] &= cache[rx] | ~mask[ry];
        }
    }

    /// <summary>
    /// this |= Mask &lt;&lt; shift
    /// </summary>
    public void ApplyOR(BitSet Mask, int shift = 0) {
        ApplyOR(Mask, Math.Max(shift, 0), n, Math.Max(-shift, 0));
    }
    /// <summary>
    /// this[l1,l1+len) |= mask[l2,l2+len)
    /// </summary>
    public void ApplyOR(BitSet Mask, int l1, int len, int l2 = 0) {
        align(ref l1, l2, ref len, n);
        align(ref l2, l1, ref len, Mask.n);

        int lx = l1 / B, ly = l1 % B, rx = (l1 + len) / B, ry = (l1 + len) % B;
        var dx = (l2 - l1) / B;
        var dy = (l2 - l1) % B;
        if (dy < 0) { dy += B; dx--; }
        var revdy = (B - dy) % B;
        cache[lx] = (lx + dx >= 0 ? Mask.bits[lx + dx] >> dy : 0) | (revdy == 0 ? 0 : Mask.bits[lx + dx + 1] << revdy);
        if (lx == rx) bits[lx] |= cache[lx] & (mask[ry] & revmask[ly]);
        else
        {
            if (revdy == 0) Buffer.BlockCopy(Mask.bits, (lx + dx + 1) * sizeof(ulong), cache, (lx + 1) * sizeof(ulong), (rx - lx) * sizeof(ulong));
            else
            {
                for (int i = lx + 1; i <= rx; i++)
                    cache[i] = Mask.bits[i + dx] >> dy | Mask.bits[i + dx + 1] << revdy;
            }
            bits[lx] |= cache[lx] & revmask[ly];
            for (int i = lx + 1; i < rx; i++)
                bits[i] |= cache[i];
            bits[rx] |= cache[rx] & mask[ry];
        }
    }

    /// <summary>
    /// this ^= Mask &lt;&lt; shift
    /// </summary>
    public void ApplyXOR(BitSet Mask, int shift = 0) {
        ApplyXOR(Mask, Math.Max(shift, 0), n, Math.Max(-shift, 0));
    }
    /// <summary>
    /// this[l1,l1+len) ^= mask[l2,l2+len)
    /// </summary>
    public void ApplyXOR(BitSet Mask, int l1, int len, int l2 = 0) {
        align(ref l1, l2, ref len, n);
        align(ref l2, l1, ref len, Mask.n);

        int lx = l1 / B, ly = l1 % B, rx = (l1 + len) / B, ry = (l1 + len) % B;
        var dx = (l2 - l1) / B;
        var dy = (l2 - l1) % B;
        if (dy < 0) { dy += B; dx--; }
        var revdy = (B - dy) % B;
        cache[lx] = (lx + dx >= 0 ? Mask.bits[lx + dx] >> dy : 0) | (revdy == 0 ? 0 : Mask.bits[lx + dx + 1] << revdy);

        if (lx == rx) bits[lx] ^= cache[lx] & (mask[ry] & revmask[ly]);
        else
        {
            if (revdy == 0) Buffer.BlockCopy(Mask.bits, (lx + dx + 1) * sizeof(ulong), cache, (lx + 1) * sizeof(ulong), (rx - lx) * sizeof(ulong));
            else
            {
                for (int i = lx + 1; i <= rx; i++)
                    cache[i] = Mask.bits[i + dx] >> dy | Mask.bits[i + dx + 1] << revdy;
            }
            bits[lx] ^= cache[lx] & revmask[ly];
            for (int i = lx + 1; i < rx; i++)
                bits[i] ^= cache[i];
            bits[rx] ^= cache[rx] & mask[ry];
        }
    }
}

#endregion
0