コード例 #1
0
        public void Solve(MyInputStream cin)
        {
            var N = cin.ReadInt();
            var M = cin.ReadInt();

            var total = 0;
            var imos  = new long[M + 2];

            for (int i = 0; i < N; ++i)
            {
                var l = cin.ReadInt();
                var r = cin.ReadInt();
                var s = cin.ReadInt();
                imos[l]     += s;
                imos[r + 1] -= s;
                total       += s;
            }

            for (int i = 1; i <= M; ++i)
            {
                imos[i] += imos[i - 1];
            }

            var min = (long)int.MaxValue;

            for (int i = 1; i <= M; ++i)
            {
                min = Math.Min(imos[i], min);
            }

            WriteLine(total - min);
        }
コード例 #2
0
        public void Solve()
        {
            var cin = new MyInputStream();
            var N   = cin.ReadInt();
            var K   = cin.ReadInt();

            // dp[????????][???????][??????????(true:0, false:1)]
            var dp = new double[N + 1, K + 2, 2];

            for (int i = 0; i < K + 1; ++i)
            {
                dp[N, i, 0] = 0;
                dp[N, i, 1] = 1;
            }

            for (int i = N - 1; i >= 0; --i)
            {
                // ?????????????
                var p = 1.0 / (i + 1.0);
                for (int j = 0; j <= K; j++)
                {
                    dp[i, j, 0] = (1 - p) * dp[i + 1, j, 0] + p * Max(dp[i + 1, j + 1, 1], dp[i + 1, j, 0]);
                    dp[i, j, 1] = (1 - p) * dp[i + 1, j, 1] + p * Max(dp[i + 1, j + 1, 1], dp[i + 1, j, 0]);
                }
            }
            WriteLine(dp[0, 0, 0]);
        }
コード例 #3
0
ファイル: 1985840.cs プロジェクト: qifanyyy/CLCDSA
        public void Solve(MyInputStream cin)
        {
            var N = cin.ReadInt();
            var M = cin.ReadInt();
            var g = new AdjacencyListGraph(N);

            for (int i = 0; i < M; ++i)
            {
                var a = cin.ReadInt() - 1;
                var b = cin.ReadInt() - 1;
                g.AddUnDirectedEdge(a, b, 1);
            }

            var dist = g.WarshallFloyd();

            for (int i = 0; i < N; ++i)
            {
                if (g[i].Count == 0)
                {
                    WriteLine(0);
                }
                else
                {
                    var cnt = 0;
                    for (int j = 0; j < N; ++j)
                    {
                        if (dist[i, j] == 2)
                        {
                            cnt++;
                        }
                    }
                    WriteLine(cnt - 1);
                }
            }
        }
コード例 #4
0
        public void Solve()
        {
            var cin = new MyInputStream();
            var N   = cin.ReadInt();
            var a   = new List <Pair <int> >(N);

            for (var i = 0; i < N; ++i)
            {
                a.Add(new Pair <int>(cin.ReadInt(), cin.ReadInt()));
            }
            a.Sort((x, y) =>
            {
                if (x.First == y.First)
                {
                    return(y.Second - x.Second);
                }
                else
                {
                    return(x.First - y.First);
                }
            });
            var tree = new SegTree(100000);
            var ans  = 0l;

            for (int i = 0; i < N; ++i)
            {
                var h   = a[i].Second;
                var now = tree.getMax(0, h) + 1;
                ans     = Max(ans, now);
                tree[h] = now;
            }
            WriteLine(ans);
        }
コード例 #5
0
ファイル: 1940159.cs プロジェクト: qifanyyy/CLCDSA
        public void Solve(MyInputStream cin)
        {
            var N = cin.ReadInt();
            var K = cin.ReadInt();
            var S = cin.Read();
            var s = new Queue <char>(S.ToCharArray().OrderBy(x => x));
            var a = new HashMap <char, int>();
            var b = new HashMap <char, int>();

            for (int i = 0; i < N; ++i)
            {
                a[S[i]]++;
                b[S[i]]++;
            }

            string T = "";

            for (int i = 0; i < N; ++i)
            {
                a[S[i]]--;
                for (int j = 0; j < 26; ++j)
                {
                    if (b[(char)(j + 'a')] > 0)
                    {
                        b[(char)(j + 'a')]--;
                        if (S[i] != (char)(j + 'a'))
                        {
                            K--;
                        }

                        int diff = 0;
                        for (int k = 0; k < 26; ++k)
                        {
                            diff += Abs(a[(char)(k + 'a')] - b[(char)(k + 'a')]);
                        }

                        if (diff / 2 <= K)
                        {
                            T += (char)(j + 'a');
                            break;
                        }
                        else
                        {
                            if (S[i] != (char)(j + 'a'))
                            {
                                K++;
                            }
                            b[(char)(j + 'a')]++;
                        }
                    }
                }
            }

            WriteLine(T);
        }
コード例 #6
0
        public void Solve(MyInputStream cin)
        {
            var N = cin.ReadInt();
            var M = cin.ReadInt();
            var g = new Graph(N);
            var f = new Graph(N);

            for (int i = 0; i < M; i++)
            {
                var u = cin.ReadInt() - 1;
                var v = cin.ReadInt() - 1;
                var l = cin.ReadInt();
                g.AddUnDirectedEdge(u, v, l);
                if (u != 0 && v != 0)
                {
                    f.AddUnDirectedEdge(u, v, l);
                }
            }
            var dist = f.WarshallFloyd();

            if (g[0].Count < 2)
            {
                WriteLine(-1);
                return;
            }

            var min = long.MaxValue;

            for (int i = 0; i < g[0].Count - 1; ++i)
            {
                for (int j = i + 1; j < g[0].Count; ++j)
                {
                    if (i != j && dist[g[0][i].To, g[0][j].To] != long.MaxValue)
                    {
                        min = Math.Min(dist[g[0][i].To, g[0][j].To] + g[0][i].Cost + g[0][j].Cost, min);
                    }
                }
            }


            if (min == long.MaxValue)
            {
                WriteLine(-1);
            }
            else
            {
                WriteLine(min);
            }
        }
コード例 #7
0
        public void Solve(MyInputStream cin)
        {
            var N = cin.ReadInt();
            var C = cin.ReadIntArray(N);

            var a = new int[N];

            for (int i = 0; i < N; ++i)
            {
                var cnt = 0;
                for (int j = 0; j < N; ++j)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (C[i] % C[j] == 0)
                    {
                        cnt++;
                    }
                }
                a[i] = cnt;
            }

            double ret = 0;

            for (int i = 0; i < N; ++i)
            {
                ret += 1.0 * (1 + a[i] / 2) / (a[i] + 1);
            }
            WriteLine($"{ret:F15}");
        }
コード例 #8
0
ファイル: 1940377.cs プロジェクト: qifanyyy/CLCDSA
        public void Solve(MyInputStream cin)
        {
            var N = cin.ReadInt();
            var H = cin.ReadInt();
            var A = cin.ReadInt();
            var B = cin.ReadInt();
            var C = cin.ReadInt();
            var D = cin.ReadInt();
            var E = cin.ReadInt();

            long X, Y;
            long min = (long)A * N;

            for (long i = 0; i <= N; ++i)
            {
                X = i;
                if (H + X * B - (N - X) * E > 0)
                {
                    Y = 0;
                }
                else
                {
                    Y = (((N - X) * E - H - B * X) / (D + E)) + 1;
                }
                min = Min(A * X + C * Y, min);
            }
            WriteLine(min);
        }
コード例 #9
0
ファイル: 1985944.cs プロジェクト: qifanyyy/CLCDSA
        public void Solve(MyInputStream cin)
        {
            var R = cin.ReadInt();
            var C = cin.ReadInt();
            var K = cin.ReadInt();
            var s = cin.ReadStrArray(R);
            var b = new int[R, C];

            for (int c = 0; c < C; ++c)
            {
                var i = 0;
                for (int r = 0; r < R; ++r)
                {
                    if (s[r][c] != 'x')
                    {
                        i++;
                    }
                    else
                    {
                        i = 0;
                    }
                    b[r, c] = i;
                }
                i = 0;
                for (int r = R - 1; r >= 0; --r)
                {
                    if (s[r][c] != 'x')
                    {
                        i++;
                    }
                    else
                    {
                        i = 0;
                    }
                    b[r, c] = Min(i, b[r, c]);
                }
            }

            /*
             * for (int r = 0; r < R; ++r)
             * {
             *  for (int c = 0; c < C; ++c)
             *  {
             *      Write($"{b[r, c]} ");
             *  }
             *  WriteLine();
             * }
             */

            var cnt = 0;

            for (int r = K - 1; r < R - K + 1; ++r)
            {
                for (int c = K - 1; c < C - K + 1; ++c)
                {
                    var flag = true;
                    for (int k = -K + 1; k < K; ++k)
                    {
                        var nx = c + k;
                        if (nx < 0 || nx >= C)
                        {
                            flag = false; break;
                        }
                        if (K - Math.Abs(k) > b[r, nx])
                        {
                            flag = false; break;
                        }
                    }
                    if (flag)
                    {
                        Error.WriteLine($"({c}, {r})"); cnt++;
                    }
                }
            }
            WriteLine(cnt);
        }