답안 #255322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255322 2020-07-31T17:29:59 Z model_code Cryptography (NOI20_crypto) Java 11
100 / 100
494 ms 21268 KB
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;

public class Crypto {
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }
    }

    public static void main(String[] args) throws IOException {
        Reader reader = new Reader();
        int N = reader.nextInt();
        int[] P = new int[N + 1];
        int[] P2 = new int[N + 1];
        long[] F = new long[N];
        long ANS = 1;
        final long MOD = 1000000007;
        for(int a = 1; a <= N; ++a) {
            P[a] = reader.nextInt();
            P2[a] = P[a];
        }
        Arrays.sort(P2, 1, N + 1);
        for (int a = 1; a <= N; ++a)
            P[a] = Arrays.binarySearch(P2, 1, N + 1, P[a]);
        F[0] = 1;
        for (int a = 1; a < N; ++a) {
            F[a] = F[a - 1] * a;
            F[a] %= MOD;
        }
        int[] FT = new int[N + 1];
        for (int a = 1; a <= N; ++a) {
            FT[a] += 1;
            int b = a + (a & -a);
            if (b <= N) FT[b] += FT[a];
        }
        for (int a = 1; a <= N; ++a) {
            int order = 0;
            for (int x = P[a]; x != 0; x -= x & -x) order += FT[x];
            ANS += (order - 1) * F[N - a];
            ANS %= MOD;
            for (int x = P[a]; x <= N; x += x & -x) --FT[x];
        }
        System.out.println(ANS);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 10164 KB Output is correct
2 Correct 84 ms 9900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 10164 KB Output is correct
2 Correct 84 ms 9900 KB Output is correct
3 Correct 87 ms 10200 KB Output is correct
4 Correct 83 ms 10140 KB Output is correct
5 Correct 78 ms 9896 KB Output is correct
6 Correct 81 ms 10008 KB Output is correct
7 Correct 89 ms 10044 KB Output is correct
8 Correct 84 ms 10180 KB Output is correct
9 Correct 82 ms 10136 KB Output is correct
10 Correct 79 ms 9980 KB Output is correct
11 Correct 86 ms 10184 KB Output is correct
12 Correct 84 ms 10160 KB Output is correct
13 Correct 86 ms 10116 KB Output is correct
14 Correct 81 ms 10152 KB Output is correct
15 Correct 82 ms 10044 KB Output is correct
16 Correct 81 ms 10272 KB Output is correct
17 Correct 73 ms 10040 KB Output is correct
18 Correct 73 ms 10164 KB Output is correct
19 Correct 95 ms 10312 KB Output is correct
20 Correct 82 ms 10252 KB Output is correct
21 Correct 76 ms 10156 KB Output is correct
22 Correct 82 ms 10152 KB Output is correct
23 Correct 94 ms 10188 KB Output is correct
24 Correct 98 ms 10020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 9824 KB Output is correct
2 Correct 256 ms 18824 KB Output is correct
3 Correct 250 ms 16740 KB Output is correct
4 Correct 219 ms 16964 KB Output is correct
5 Correct 195 ms 17096 KB Output is correct
6 Correct 241 ms 16924 KB Output is correct
7 Correct 203 ms 17032 KB Output is correct
8 Correct 219 ms 17076 KB Output is correct
9 Correct 213 ms 16904 KB Output is correct
10 Correct 224 ms 17368 KB Output is correct
11 Correct 225 ms 16908 KB Output is correct
12 Correct 278 ms 20392 KB Output is correct
13 Correct 201 ms 17060 KB Output is correct
14 Correct 211 ms 16748 KB Output is correct
15 Correct 202 ms 16916 KB Output is correct
16 Correct 195 ms 16836 KB Output is correct
17 Correct 212 ms 16944 KB Output is correct
18 Correct 210 ms 16912 KB Output is correct
19 Correct 287 ms 20440 KB Output is correct
20 Correct 189 ms 16936 KB Output is correct
21 Correct 224 ms 16836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 10232 KB Output is correct
2 Correct 221 ms 18896 KB Output is correct
3 Correct 215 ms 18532 KB Output is correct
4 Correct 222 ms 18492 KB Output is correct
5 Correct 222 ms 17896 KB Output is correct
6 Correct 239 ms 18492 KB Output is correct
7 Correct 248 ms 18048 KB Output is correct
8 Correct 242 ms 18068 KB Output is correct
9 Correct 283 ms 18840 KB Output is correct
10 Correct 216 ms 18080 KB Output is correct
11 Correct 257 ms 18108 KB Output is correct
12 Correct 243 ms 18224 KB Output is correct
13 Correct 209 ms 18436 KB Output is correct
14 Correct 215 ms 18380 KB Output is correct
15 Correct 227 ms 18196 KB Output is correct
16 Correct 233 ms 18560 KB Output is correct
17 Correct 214 ms 18788 KB Output is correct
18 Correct 239 ms 18108 KB Output is correct
19 Correct 219 ms 18112 KB Output is correct
20 Correct 219 ms 18176 KB Output is correct
21 Correct 231 ms 18304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 10268 KB Output is correct
2 Correct 91 ms 11076 KB Output is correct
3 Correct 99 ms 11120 KB Output is correct
4 Correct 100 ms 11128 KB Output is correct
5 Correct 93 ms 10948 KB Output is correct
6 Correct 95 ms 11304 KB Output is correct
7 Correct 93 ms 11076 KB Output is correct
8 Correct 87 ms 11112 KB Output is correct
9 Correct 93 ms 11000 KB Output is correct
10 Correct 89 ms 11000 KB Output is correct
11 Correct 87 ms 11080 KB Output is correct
12 Correct 90 ms 11060 KB Output is correct
13 Correct 88 ms 11124 KB Output is correct
14 Correct 86 ms 11252 KB Output is correct
15 Correct 74 ms 10164 KB Output is correct
16 Correct 86 ms 11256 KB Output is correct
17 Correct 82 ms 11128 KB Output is correct
18 Correct 84 ms 11128 KB Output is correct
19 Correct 87 ms 11132 KB Output is correct
20 Correct 83 ms 11256 KB Output is correct
21 Correct 84 ms 11252 KB Output is correct
22 Correct 86 ms 10984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 10164 KB Output is correct
2 Correct 84 ms 9900 KB Output is correct
3 Correct 87 ms 10200 KB Output is correct
4 Correct 83 ms 10140 KB Output is correct
5 Correct 78 ms 9896 KB Output is correct
6 Correct 81 ms 10008 KB Output is correct
7 Correct 89 ms 10044 KB Output is correct
8 Correct 84 ms 10180 KB Output is correct
9 Correct 82 ms 10136 KB Output is correct
10 Correct 79 ms 9980 KB Output is correct
11 Correct 86 ms 10184 KB Output is correct
12 Correct 84 ms 10160 KB Output is correct
13 Correct 86 ms 10116 KB Output is correct
14 Correct 81 ms 10152 KB Output is correct
15 Correct 82 ms 10044 KB Output is correct
16 Correct 81 ms 10272 KB Output is correct
17 Correct 73 ms 10040 KB Output is correct
18 Correct 73 ms 10164 KB Output is correct
19 Correct 95 ms 10312 KB Output is correct
20 Correct 82 ms 10252 KB Output is correct
21 Correct 76 ms 10156 KB Output is correct
22 Correct 82 ms 10152 KB Output is correct
23 Correct 94 ms 10188 KB Output is correct
24 Correct 98 ms 10020 KB Output is correct
25 Correct 98 ms 10268 KB Output is correct
26 Correct 91 ms 11076 KB Output is correct
27 Correct 99 ms 11120 KB Output is correct
28 Correct 100 ms 11128 KB Output is correct
29 Correct 93 ms 10948 KB Output is correct
30 Correct 95 ms 11304 KB Output is correct
31 Correct 93 ms 11076 KB Output is correct
32 Correct 87 ms 11112 KB Output is correct
33 Correct 93 ms 11000 KB Output is correct
34 Correct 89 ms 11000 KB Output is correct
35 Correct 87 ms 11080 KB Output is correct
36 Correct 90 ms 11060 KB Output is correct
37 Correct 88 ms 11124 KB Output is correct
38 Correct 86 ms 11252 KB Output is correct
39 Correct 74 ms 10164 KB Output is correct
40 Correct 86 ms 11256 KB Output is correct
41 Correct 82 ms 11128 KB Output is correct
42 Correct 84 ms 11128 KB Output is correct
43 Correct 87 ms 11132 KB Output is correct
44 Correct 83 ms 11256 KB Output is correct
45 Correct 84 ms 11252 KB Output is correct
46 Correct 86 ms 10984 KB Output is correct
47 Correct 72 ms 10052 KB Output is correct
48 Correct 86 ms 11252 KB Output is correct
49 Correct 102 ms 11280 KB Output is correct
50 Correct 85 ms 11252 KB Output is correct
51 Correct 89 ms 11268 KB Output is correct
52 Correct 89 ms 11028 KB Output is correct
53 Correct 89 ms 11240 KB Output is correct
54 Correct 87 ms 11128 KB Output is correct
55 Correct 83 ms 11368 KB Output is correct
56 Correct 89 ms 11192 KB Output is correct
57 Correct 88 ms 11128 KB Output is correct
58 Correct 85 ms 10356 KB Output is correct
59 Correct 91 ms 10856 KB Output is correct
60 Correct 90 ms 11368 KB Output is correct
61 Correct 74 ms 10228 KB Output is correct
62 Correct 87 ms 11240 KB Output is correct
63 Correct 88 ms 11236 KB Output is correct
64 Correct 88 ms 11240 KB Output is correct
65 Correct 88 ms 11252 KB Output is correct
66 Correct 97 ms 11536 KB Output is correct
67 Correct 90 ms 11128 KB Output is correct
68 Correct 90 ms 10600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 10232 KB Output is correct
2 Correct 221 ms 18896 KB Output is correct
3 Correct 215 ms 18532 KB Output is correct
4 Correct 222 ms 18492 KB Output is correct
5 Correct 222 ms 17896 KB Output is correct
6 Correct 239 ms 18492 KB Output is correct
7 Correct 248 ms 18048 KB Output is correct
8 Correct 242 ms 18068 KB Output is correct
9 Correct 283 ms 18840 KB Output is correct
10 Correct 216 ms 18080 KB Output is correct
11 Correct 257 ms 18108 KB Output is correct
12 Correct 243 ms 18224 KB Output is correct
13 Correct 209 ms 18436 KB Output is correct
14 Correct 215 ms 18380 KB Output is correct
15 Correct 227 ms 18196 KB Output is correct
16 Correct 233 ms 18560 KB Output is correct
17 Correct 214 ms 18788 KB Output is correct
18 Correct 239 ms 18108 KB Output is correct
19 Correct 219 ms 18112 KB Output is correct
20 Correct 219 ms 18176 KB Output is correct
21 Correct 231 ms 18304 KB Output is correct
22 Correct 98 ms 10268 KB Output is correct
23 Correct 91 ms 11076 KB Output is correct
24 Correct 99 ms 11120 KB Output is correct
25 Correct 100 ms 11128 KB Output is correct
26 Correct 93 ms 10948 KB Output is correct
27 Correct 95 ms 11304 KB Output is correct
28 Correct 93 ms 11076 KB Output is correct
29 Correct 87 ms 11112 KB Output is correct
30 Correct 93 ms 11000 KB Output is correct
31 Correct 89 ms 11000 KB Output is correct
32 Correct 87 ms 11080 KB Output is correct
33 Correct 90 ms 11060 KB Output is correct
34 Correct 88 ms 11124 KB Output is correct
35 Correct 86 ms 11252 KB Output is correct
36 Correct 74 ms 10164 KB Output is correct
37 Correct 86 ms 11256 KB Output is correct
38 Correct 82 ms 11128 KB Output is correct
39 Correct 84 ms 11128 KB Output is correct
40 Correct 87 ms 11132 KB Output is correct
41 Correct 83 ms 11256 KB Output is correct
42 Correct 84 ms 11252 KB Output is correct
43 Correct 86 ms 10984 KB Output is correct
44 Correct 77 ms 10132 KB Output is correct
45 Correct 337 ms 20868 KB Output is correct
46 Correct 317 ms 18532 KB Output is correct
47 Correct 322 ms 18840 KB Output is correct
48 Correct 355 ms 20932 KB Output is correct
49 Correct 332 ms 18040 KB Output is correct
50 Correct 429 ms 21004 KB Output is correct
51 Correct 330 ms 18672 KB Output is correct
52 Correct 346 ms 20692 KB Output is correct
53 Correct 313 ms 18960 KB Output is correct
54 Correct 340 ms 21112 KB Output is correct
55 Correct 317 ms 18336 KB Output is correct
56 Correct 392 ms 20896 KB Output is correct
57 Correct 306 ms 18568 KB Output is correct
58 Correct 69 ms 10104 KB Output is correct
59 Correct 363 ms 20832 KB Output is correct
60 Correct 459 ms 20412 KB Output is correct
61 Correct 432 ms 20704 KB Output is correct
62 Correct 347 ms 20988 KB Output is correct
63 Correct 335 ms 21196 KB Output is correct
64 Correct 334 ms 20624 KB Output is correct
65 Correct 330 ms 18504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 10164 KB Output is correct
2 Correct 84 ms 9900 KB Output is correct
3 Correct 87 ms 10200 KB Output is correct
4 Correct 83 ms 10140 KB Output is correct
5 Correct 78 ms 9896 KB Output is correct
6 Correct 81 ms 10008 KB Output is correct
7 Correct 89 ms 10044 KB Output is correct
8 Correct 84 ms 10180 KB Output is correct
9 Correct 82 ms 10136 KB Output is correct
10 Correct 79 ms 9980 KB Output is correct
11 Correct 86 ms 10184 KB Output is correct
12 Correct 84 ms 10160 KB Output is correct
13 Correct 86 ms 10116 KB Output is correct
14 Correct 81 ms 10152 KB Output is correct
15 Correct 82 ms 10044 KB Output is correct
16 Correct 81 ms 10272 KB Output is correct
17 Correct 73 ms 10040 KB Output is correct
18 Correct 73 ms 10164 KB Output is correct
19 Correct 95 ms 10312 KB Output is correct
20 Correct 82 ms 10252 KB Output is correct
21 Correct 76 ms 10156 KB Output is correct
22 Correct 82 ms 10152 KB Output is correct
23 Correct 94 ms 10188 KB Output is correct
24 Correct 98 ms 10020 KB Output is correct
25 Correct 88 ms 9824 KB Output is correct
26 Correct 256 ms 18824 KB Output is correct
27 Correct 250 ms 16740 KB Output is correct
28 Correct 219 ms 16964 KB Output is correct
29 Correct 195 ms 17096 KB Output is correct
30 Correct 241 ms 16924 KB Output is correct
31 Correct 203 ms 17032 KB Output is correct
32 Correct 219 ms 17076 KB Output is correct
33 Correct 213 ms 16904 KB Output is correct
34 Correct 224 ms 17368 KB Output is correct
35 Correct 225 ms 16908 KB Output is correct
36 Correct 278 ms 20392 KB Output is correct
37 Correct 201 ms 17060 KB Output is correct
38 Correct 211 ms 16748 KB Output is correct
39 Correct 202 ms 16916 KB Output is correct
40 Correct 195 ms 16836 KB Output is correct
41 Correct 212 ms 16944 KB Output is correct
42 Correct 210 ms 16912 KB Output is correct
43 Correct 287 ms 20440 KB Output is correct
44 Correct 189 ms 16936 KB Output is correct
45 Correct 224 ms 16836 KB Output is correct
46 Correct 71 ms 10232 KB Output is correct
47 Correct 221 ms 18896 KB Output is correct
48 Correct 215 ms 18532 KB Output is correct
49 Correct 222 ms 18492 KB Output is correct
50 Correct 222 ms 17896 KB Output is correct
51 Correct 239 ms 18492 KB Output is correct
52 Correct 248 ms 18048 KB Output is correct
53 Correct 242 ms 18068 KB Output is correct
54 Correct 283 ms 18840 KB Output is correct
55 Correct 216 ms 18080 KB Output is correct
56 Correct 257 ms 18108 KB Output is correct
57 Correct 243 ms 18224 KB Output is correct
58 Correct 209 ms 18436 KB Output is correct
59 Correct 215 ms 18380 KB Output is correct
60 Correct 227 ms 18196 KB Output is correct
61 Correct 233 ms 18560 KB Output is correct
62 Correct 214 ms 18788 KB Output is correct
63 Correct 239 ms 18108 KB Output is correct
64 Correct 219 ms 18112 KB Output is correct
65 Correct 219 ms 18176 KB Output is correct
66 Correct 231 ms 18304 KB Output is correct
67 Correct 98 ms 10268 KB Output is correct
68 Correct 91 ms 11076 KB Output is correct
69 Correct 99 ms 11120 KB Output is correct
70 Correct 100 ms 11128 KB Output is correct
71 Correct 93 ms 10948 KB Output is correct
72 Correct 95 ms 11304 KB Output is correct
73 Correct 93 ms 11076 KB Output is correct
74 Correct 87 ms 11112 KB Output is correct
75 Correct 93 ms 11000 KB Output is correct
76 Correct 89 ms 11000 KB Output is correct
77 Correct 87 ms 11080 KB Output is correct
78 Correct 90 ms 11060 KB Output is correct
79 Correct 88 ms 11124 KB Output is correct
80 Correct 86 ms 11252 KB Output is correct
81 Correct 74 ms 10164 KB Output is correct
82 Correct 86 ms 11256 KB Output is correct
83 Correct 82 ms 11128 KB Output is correct
84 Correct 84 ms 11128 KB Output is correct
85 Correct 87 ms 11132 KB Output is correct
86 Correct 83 ms 11256 KB Output is correct
87 Correct 84 ms 11252 KB Output is correct
88 Correct 86 ms 10984 KB Output is correct
89 Correct 72 ms 10052 KB Output is correct
90 Correct 86 ms 11252 KB Output is correct
91 Correct 102 ms 11280 KB Output is correct
92 Correct 85 ms 11252 KB Output is correct
93 Correct 89 ms 11268 KB Output is correct
94 Correct 89 ms 11028 KB Output is correct
95 Correct 89 ms 11240 KB Output is correct
96 Correct 87 ms 11128 KB Output is correct
97 Correct 83 ms 11368 KB Output is correct
98 Correct 89 ms 11192 KB Output is correct
99 Correct 88 ms 11128 KB Output is correct
100 Correct 85 ms 10356 KB Output is correct
101 Correct 91 ms 10856 KB Output is correct
102 Correct 90 ms 11368 KB Output is correct
103 Correct 74 ms 10228 KB Output is correct
104 Correct 87 ms 11240 KB Output is correct
105 Correct 88 ms 11236 KB Output is correct
106 Correct 88 ms 11240 KB Output is correct
107 Correct 88 ms 11252 KB Output is correct
108 Correct 97 ms 11536 KB Output is correct
109 Correct 90 ms 11128 KB Output is correct
110 Correct 90 ms 10600 KB Output is correct
111 Correct 77 ms 10132 KB Output is correct
112 Correct 337 ms 20868 KB Output is correct
113 Correct 317 ms 18532 KB Output is correct
114 Correct 322 ms 18840 KB Output is correct
115 Correct 355 ms 20932 KB Output is correct
116 Correct 332 ms 18040 KB Output is correct
117 Correct 429 ms 21004 KB Output is correct
118 Correct 330 ms 18672 KB Output is correct
119 Correct 346 ms 20692 KB Output is correct
120 Correct 313 ms 18960 KB Output is correct
121 Correct 340 ms 21112 KB Output is correct
122 Correct 317 ms 18336 KB Output is correct
123 Correct 392 ms 20896 KB Output is correct
124 Correct 306 ms 18568 KB Output is correct
125 Correct 69 ms 10104 KB Output is correct
126 Correct 363 ms 20832 KB Output is correct
127 Correct 459 ms 20412 KB Output is correct
128 Correct 432 ms 20704 KB Output is correct
129 Correct 347 ms 20988 KB Output is correct
130 Correct 335 ms 21196 KB Output is correct
131 Correct 334 ms 20624 KB Output is correct
132 Correct 330 ms 18504 KB Output is correct
133 Correct 84 ms 10100 KB Output is correct
134 Correct 325 ms 18312 KB Output is correct
135 Correct 494 ms 21196 KB Output is correct
136 Correct 314 ms 17980 KB Output is correct
137 Correct 337 ms 18964 KB Output is correct
138 Correct 363 ms 20912 KB Output is correct
139 Correct 316 ms 18512 KB Output is correct
140 Correct 344 ms 21004 KB Output is correct
141 Correct 458 ms 21204 KB Output is correct
142 Correct 353 ms 20988 KB Output is correct
143 Correct 365 ms 21268 KB Output is correct
144 Correct 475 ms 21172 KB Output is correct
145 Correct 336 ms 18824 KB Output is correct
146 Correct 397 ms 20848 KB Output is correct
147 Correct 70 ms 10216 KB Output is correct
148 Correct 423 ms 20468 KB Output is correct
149 Correct 408 ms 21044 KB Output is correct
150 Correct 413 ms 20856 KB Output is correct
151 Correct 330 ms 18824 KB Output is correct
152 Correct 311 ms 18968 KB Output is correct
153 Correct 343 ms 20996 KB Output is correct
154 Correct 371 ms 21196 KB Output is correct