結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー りあんりあん
提出日時 2015-04-18 23:29:09
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,430 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 115,880 KB
実行使用メモリ 36,516 KB
最終ジャッジ日時 2024-04-25 22:42:50
合計ジャッジ時間 6,773 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,584 KB
testcase_01 AC 28 ms
25,328 KB
testcase_02 AC 29 ms
25,328 KB
testcase_03 AC 28 ms
27,468 KB
testcase_04 AC 28 ms
25,432 KB
testcase_05 AC 28 ms
25,324 KB
testcase_06 AC 30 ms
27,476 KB
testcase_07 AC 778 ms
28,568 KB
testcase_08 AC 703 ms
30,736 KB
testcase_09 AC 328 ms
28,720 KB
testcase_10 AC 485 ms
28,644 KB
testcase_11 AC 844 ms
28,948 KB
testcase_12 AC 29 ms
25,452 KB
testcase_13 AC 27 ms
27,212 KB
testcase_14 AC 175 ms
26,592 KB
testcase_15 AC 528 ms
36,516 KB
testcase_16 WA -
testcase_17 AC 60 ms
26,204 KB
testcase_18 AC 969 ms
30,852 KB
testcase_19 AC 40 ms
25,652 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.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