Submission #75599410
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>#include <string.h>int cmp(const void* x, const void* y) {int a = *(const int*)x, b = *(const int*)y;return (a > b) - (a < b);}int zac;int zal[212345];int value[212345];int* zaq(int q) {int l = 0, r = zac - 1;while (l <= r) {int m = l + (r - l) / 2;if (zal[m] == q) return &value[m];else if (zal[m] < q) l = m + 1;else r = m - 1;}return NULL;}int N;int A[212345];int main(void) {int i;int ans = 0;if (scanf("%d", &N) != 1) return 1;for (i = 0; i < N; i++) {if (scanf("%d", &A[i]) != 1) return 1;}memcpy(zal, A, sizeof(*A) * N);qsort(zal, N, sizeof(*zal), cmp);for (i = 1, zac = 1; i < N; i++) {if (zal[i] != zal[zac - 1]) zal[zac++] = zal[i];}for (i = N - 1; i >= 0; i--) {/* 「この先の、この要素値+1から始まる連続記録」+1 = この要素での記録 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void* x, const void* y) {
int a = *(const int*)x, b = *(const int*)y;
return (a > b) - (a < b);
}
int zac;
int zal[212345];
int value[212345];
int* zaq(int q) {
int l = 0, r = zac - 1;
while (l <= r) {
int m = l + (r - l) / 2;
if (zal[m] == q) return &value[m];
else if (zal[m] < q) l = m + 1;
else r = m - 1;
}
return NULL;
}
int N;
int A[212345];
int main(void) {
int i;
int ans = 0;
if (scanf("%d", &N) != 1) return 1;
for (i = 0; i < N; i++) {
if (scanf("%d", &A[i]) != 1) return 1;
}
memcpy(zal, A, sizeof(*A) * N);
qsort(zal, N, sizeof(*zal), cmp);
for (i = 1, zac = 1; i < N; i++) {
if (zal[i] != zal[zac - 1]) zal[zac++] = zal[i];
}
for (i = N - 1; i >= 0; i--) {
/* 「この先の、この要素値+1から始まる連続記録」+1 = この要素での記録 */
int *pnext = zaq(A[i] + 1);
int next_ans = pnext == NULL ? 0 : *pnext;
int cur_ans;
int *pcur = zaq(A[i]);
if (pcur == NULL) return 72;
cur_ans = next_ans + 1;
if (*pcur < cur_ans) *pcur = cur_ans;
if (cur_ans > ans) ans = cur_ans;
}
printf("%d\n", ans);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Max Straight |
| User | mikecat |
| Language | C23 (GCC 14.2.0) |
| Score | 400 |
| Code Size | 1220 Byte |
| Status | AC |
| Exec Time | 78 ms |
| Memory | 4156 KiB |
Judge Result
| Set Name | Sample | All | after_contest | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | 0 / 0 | ||||||
| Status |
|
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt |
| after_contest | 02_after_contest_00.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 1652 KiB |
| 00_sample_01.txt | AC | 1 ms | 1604 KiB |
| 00_sample_02.txt | AC | 0 ms | 1628 KiB |
| 01_random_00.txt | AC | 0 ms | 1712 KiB |
| 01_random_01.txt | AC | 0 ms | 1636 KiB |
| 01_random_02.txt | AC | 1 ms | 1636 KiB |
| 01_random_03.txt | AC | 39 ms | 4044 KiB |
| 01_random_04.txt | AC | 41 ms | 4044 KiB |
| 01_random_05.txt | AC | 44 ms | 3036 KiB |
| 01_random_06.txt | AC | 21 ms | 2332 KiB |
| 01_random_07.txt | AC | 78 ms | 4156 KiB |
| 01_random_08.txt | AC | 20 ms | 2560 KiB |
| 01_random_09.txt | AC | 1 ms | 1560 KiB |
| 01_random_10.txt | AC | 51 ms | 3968 KiB |
| 01_random_11.txt | AC | 51 ms | 3896 KiB |
| 01_random_12.txt | AC | 5 ms | 1968 KiB |
| 01_random_13.txt | AC | 55 ms | 4060 KiB |
| 01_random_14.txt | AC | 2 ms | 1908 KiB |
| 01_random_15.txt | AC | 60 ms | 3912 KiB |
| 01_random_16.txt | AC | 30 ms | 2696 KiB |
| 01_random_17.txt | AC | 52 ms | 4080 KiB |
| 01_random_18.txt | AC | 52 ms | 4112 KiB |
| 01_random_19.txt | AC | 57 ms | 4064 KiB |
| 01_random_20.txt | AC | 40 ms | 3344 KiB |
| 01_random_21.txt | AC | 66 ms | 4072 KiB |
| 01_random_22.txt | AC | 5 ms | 1880 KiB |
| 02_after_contest_00.txt | AC | 29 ms | 3740 KiB |