結果

問題 No.1996 <><
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-28 00:04:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 2,774 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 70,288 KB
実行使用メモリ 47,708 KB
最終ジャッジ日時 2023-09-28 00:04:34
合計ジャッジ時間 9,104 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
22,572 KB
testcase_01 AC 63 ms
24,640 KB
testcase_02 AC 60 ms
22,820 KB
testcase_03 AC 63 ms
24,656 KB
testcase_04 AC 61 ms
22,604 KB
testcase_05 AC 61 ms
22,536 KB
testcase_06 AC 72 ms
20,632 KB
testcase_07 AC 63 ms
22,628 KB
testcase_08 AC 63 ms
22,704 KB
testcase_09 AC 62 ms
22,640 KB
testcase_10 AC 61 ms
22,660 KB
testcase_11 AC 152 ms
43,440 KB
testcase_12 AC 224 ms
41,480 KB
testcase_13 AC 238 ms
45,548 KB
testcase_14 AC 245 ms
43,492 KB
testcase_15 AC 204 ms
44,040 KB
testcase_16 AC 215 ms
42,044 KB
testcase_17 AC 235 ms
44,236 KB
testcase_18 AC 206 ms
45,836 KB
testcase_19 AC 183 ms
42,068 KB
testcase_20 AC 179 ms
43,688 KB
testcase_21 AC 216 ms
42,684 KB
testcase_22 AC 240 ms
41,360 KB
testcase_23 AC 89 ms
22,884 KB
testcase_24 AC 174 ms
47,708 KB
testcase_25 AC 117 ms
21,048 KB
testcase_26 AC 151 ms
33,640 KB
testcase_27 AC 84 ms
25,036 KB
testcase_28 AC 70 ms
24,708 KB
testcase_29 AC 97 ms
29,060 KB
testcase_30 AC 71 ms
22,760 KB
testcase_31 AC 78 ms
25,096 KB
testcase_32 AC 67 ms
24,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;;
        var n = c[0];
        var a = Compress(NList);
        var s = ReadLine();
        var dp = Enumerable.Repeat(1L, n).ToArray();
        var mod = 1_000_000_007;
        for (var i = 0; i < s.Length; ++i)
        {
            var ndp = new long[n];
            var ft = new FenwickTree(n + 1);
            for (var j = 0; j < n; ++j)
            {
                if (s[i] == '<') ndp[j] = ft.Sum(a[j] - 1) % mod;
                else ndp[j] = (ft.Sum(n) - ft.Sum(a[j])) % mod;
                ft.Add(a[j], dp[j]);
            }
            dp = ndp;
        }
        var ans = 0L;
        for (var i = 0; i < n; ++i) ans = (ans + dp[i]) % mod;
        WriteLine(ans);
    }
    static int[] Compress(int[] a)
    {
        var list = new List<int>(new HashSet<int>(a));
        list.Sort();
        var dic = new Dictionary<int, int>();
        for (var i = 0; i < list.Count; ++i) dic[list[i]] = i + 1;
        var ans = new int[a.Length];
        for (var i = 0; i < a.Length; ++i) ans[i] = dic[a[i]];
        return ans;
    }
    class FenwickTree
    {
        int size;
        long[] tree;
        public FenwickTree(int size)
        {
            this.size = size;
            tree = new long[size + 2];
        }
        public void Add(int index, long value)
        {
            ++index;
            for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
        }
        /// <summary>先頭からindexまでの和(include index)</summary>
        public long Sum(int index)
        {
            ++index;
            var sum = 0L;
            for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
            return sum;
        }
        /// <summary>Sum(x) >= value となる最小のxを求める</summary>
        // 各要素は非負であること
        public int LowerBound(long value)
        {
            if (value < 0) return -1;
            var x = 0;
            var b = 1;
            while (b * 2 <= size) b <<= 1;
            for (var k = b; k > 0; k >>= 1)
            {
                if (x + k <= size && tree[x + k] < value)
                {
                    value -= tree[x + k];
                    x += k;
                }
            }
            return x;
        }
    }
}
0