Submission #172901


Source Code Expand

Copy
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    Dictionary<int, int> curr, sum;

    void Solve()
    {
        int N = reader.Int(), Q = reader.Int();
        int[] A = reader.IntArray(N);
        int[] Query = reader.IntArray(Q);
        curr = new Dictionary<int, int>();
        sum = new Dictionary<int, int>();

        Array.ForEach(A, a => Update(a));
        Array.ForEach(Query, q => Console.WriteLine(sum.ContainsKey(q) ? sum[q] : 0));
        Console.ReadLine();
    }

    void Update(int a)
    {
        var next = new Dictionary<int, int>();
        Add(a, 1, next);
        Add(a, 1, sum);

        foreach (var other in curr.Keys)
        {
            int g = GCD(a, other);
            Add(g, curr[other], next);
            Add(g, curr[other], sum);
        }
        curr = next;
    }

    void Add(int key, int val, Dictionary<int, int> dic)
    {
        if (dic.ContainsKey(key)) dic[key] += val;
        else dic[key] = val;
    }

    static int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }




    static void Main() { new Program().Solve(); }
    static Reader reader = new Reader(Console.In);

    class Reader
    {
        private readonly TextReader reader;
        private readonly char[] separator = new char[] { ' ' };
        private string[] s = new string[0];
        private int i;
        public Reader(TextReader r) { reader = r; }
        public bool HasNext() { return Enqueue(); }
        public string String() { return Dequeue(); }
        public int Int() { return int.Parse(Dequeue()); }
        public long Long() { return long.Parse(Dequeue()); }
        public double Double() { return double.Parse(Dequeue()); }
        public int[] IntLine() { return Array.ConvertAll(Line().Split(), int.Parse); }
        public int[] IntArray(int N) { return Enumerable.Range(0, N).Select(i => Int()).ToArray(); }
        public int[][] IntGrid(int H) { return Enumerable.Range(0, H).Select(i => IntLine()).ToArray(); }
        public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Line()).ToArray(); }
        public string Line() { return reader.ReadLine().Trim(); }
        private bool Enqueue()
        {
            if (i < s.Length) return true;
            string line = reader.ReadLine();
            if (string.IsNullOrEmpty(line)) return false;
            s = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return true;
        }
        private string Dequeue() { Enqueue(); return s[i++]; }
    }
}

Submission Info

Submission Time
Task D - GCD区間
User eitaho
Language C# (Mono 2.10.8.1)
Score 0
Code Size 2691 Byte
Status WA
Exec Time 1464 ms
Memory 16328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 3
AC × 8
WA × 22
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 175 ms 9012 KB
subtask0_sample_02.txt AC 179 ms 9016 KB
subtask0_sample_03.txt AC 173 ms 9008 KB
subtask1_01.txt AC 195 ms 9256 KB
subtask1_02.txt AC 191 ms 9260 KB
subtask1_03.txt AC 197 ms 9300 KB
subtask1_04.txt WA 1443 ms 16328 KB
subtask1_05.txt WA 1464 ms 16212 KB
subtask1_06.txt AC 358 ms 10384 KB
subtask1_07.txt WA 335 ms 10632 KB
subtask1_08.txt WA 343 ms 10504 KB
subtask1_09.txt WA 451 ms 10640 KB
subtask1_10.txt WA 443 ms 10516 KB
subtask1_11.txt WA 1371 ms 16300 KB
subtask1_12.txt WA 375 ms 10500 KB
subtask1_13.txt WA 450 ms 10632 KB
subtask1_14.txt WA 379 ms 10640 KB
subtask1_15.txt WA 426 ms 10508 KB
subtask1_16.txt WA 482 ms 10200 KB
subtask1_17.txt WA 485 ms 10504 KB
subtask1_18.txt WA 388 ms 10488 KB
subtask1_19.txt WA 388 ms 10440 KB
subtask1_20.txt WA 383 ms 10612 KB
subtask1_21.txt WA 357 ms 10632 KB
subtask1_22.txt WA 377 ms 10512 KB
subtask1_23.txt WA 396 ms 10628 KB
subtask1_24.txt WA 365 ms 10512 KB
subtask1_25.txt WA 377 ms 10552 KB
subtask1_26.txt AC 1137 ms 11132 KB
subtask1_27.txt WA 1332 ms 10888 KB