結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー りあんりあん
提出日時 2015-04-18 22:47:23
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,430 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 106,644 KB
実行使用メモリ 245,648 KB
最終ジャッジ日時 2023-09-17 16:45:40
合計ジャッジ時間 10,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
21,836 KB
testcase_01 AC 65 ms
21,832 KB
testcase_02 AC 67 ms
21,824 KB
testcase_03 AC 67 ms
23,880 KB
testcase_04 AC 67 ms
21,824 KB
testcase_05 AC 66 ms
21,844 KB
testcase_06 AC 65 ms
21,864 KB
testcase_07 AC 67 ms
23,788 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace Solver
{
    class Program
    {
        const int M = 1000000007;
        static void Main()
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Scan sc = new Scan();
            int n = sc.Int();
            int k = 61;
            long[] a = sc.LongArray();
            MaxFlow mf = new MaxFlow(n + k + 2);
            for (int i = 0; i < n; ++i)
            {
                mf.add_edge(0, i + 1, 1, true);
                for (int j = 0; j < k; ++j)
                    if ((a[i] >> j) % 2 == 1)
                        mf.add_edge(i + 1, n + j + 1, 1, true);
            }
            for (int i = 0; i < k; ++i)
                mf.add_edge(n + i + 1, n + k + 1, 1, true);

            sw.WriteLine((long)1 << mf.run(0, n + k + 1));
            sw.Flush();
        }
    }

    class Scan
    {
        public int Int()
        {
            return int.Parse(Console.ReadLine().Trim());
        }
        public long Long()
        {
            return long.Parse(Console.ReadLine().Trim());
        }
        public string Str()
        {
            return Console.ReadLine().Trim();
        }

        public int[] IntArray()
        {
            return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
        }
        public void IntTwi(out int a, out int b)
        {
            int[] arr = IntArray();
            a = arr[0];
            b = arr[1];
        }
        public void LongTwi(out long a, out long b)
        {
            long[] arr = LongArray();
            a = arr[0];
            b = arr[1];
        }
        public void StrTwi(out string a, out string b)
        {
            string[] arr = StrArray();
            a = arr[0];
            b = arr[1];
        }

        public long[] LongArray()
        {
            return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
        }
        public string[] StrArray()
        {
            return Console.ReadLine().Trim().Split();
        }
    }
    class MaxFlow
    {
        class edge { public int to, cap, rev; }
        int V;
        List<edge>[] G;
        int[] itr, level;

        public MaxFlow(int V) // V : ten no kazu
        {
            this.V = V;
            G = new List<edge>[V];
            for (int i = 0; i < V; ++i)
                G[i] = new List<edge>();
        }

        public void add_edge(int from, int to, int cap, bool IsDirection)
        {
            G[from].Add(new edge { to = to, cap = cap, rev = G[to].Count });
            if (IsDirection)
                G[to].Add(new edge { to = from, cap = 0, rev = G[from].Count - 1 });
            else
                G[to].Add(new edge { to = from, cap = cap, rev = G[from].Count - 1 });
        }

        void bfs(int s)
        {
            level = new int[V];
            for (int i = 0; i < V; ++i)
                level[i] = -1;

            Queue<int> q = new Queue<int>();
            level[s] = 0;
            q.Enqueue(s);
            while (q.Count > 0)
            {
                int v = q.Dequeue();
                foreach (edge e in G[v])
                {
                    if (e.cap > 0 && level[e.to] < 0)
                    {
                        level[e.to] = level[v] + 1;
                        q.Enqueue(e.to);
                    }
                }
            }
        }

        int dfs(int v, int t, int f)
        {
            if (v == t) return f;
            for (int i = itr[v]; i < (int)G[v].Count; ++i)
            {
                edge e = G[v][i];
                if (e.cap > 0 && level[v] < level[e.to])
                {
                    int d = dfs(e.to, t, Math.Min(f, e.cap));
                    if (d > 0)
                    {
                        e.cap -= d;
                        G[e.to][e.rev].cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }

        public int run(int s, int t)
        {
            int ret = 0, f;
            bfs(s);
            while (level[t] >= 0)
            {
                itr = new int[V];
                while ((f = dfs(s, t, Int32.MaxValue)) > 0)
                    ret += f;

                bfs(s);
            }
            return ret;
        }
    }

}
0