結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2022-09-11 14:24:22 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 1,738 bytes |
| コンパイル時間 | 573 ms |
| コンパイル使用メモリ | 31,232 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 23:47:34 |
| 合計ジャッジ時間 | 2,417 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
#include<stdio.h>
char ss[200005];
char s[200005];
int st[200005];
int h[200005], l;
int comp_h(int a, int b)
{
if (s[st[h[a] + 1] - 1] > s[st[h[b] + 1] - 1])
return 1;
else if (s[st[h[a] + 1] - 1] < s[st[h[b] + 1] - 1])
return -1;
else if (s[st[h[a]]] > s[st[h[b]]])
return 1;
else
return -1;
}
void swap_h(int a, int b)
{
int f = h[a];
h[a] = h[b];
h[b] = f;
return;
}
void push(int ne)
{
h[l] = ne;
int p = l;
l++;
for (; p > 0; p = (p - 1) / 2)
if (comp_h((p - 1) / 2, p) > 0)
swap_h((p - 1) / 2, p);
return;
}
int pop()
{
l--;
swap_h(0, l);
int p = 0;
for (;;)
{
if (2 * p + 2 < l)
{
if (comp_h(2 * p + 1, 2 * p + 2) > 0)
{
if (comp_h(p, 2 * p + 2) > 0)
swap_h(p, 2 * p + 2);
p = 2 * p + 2;
}
else
{
if (comp_h(p, 2 * p + 1) > 0)
swap_h(p, 2 * p + 1);
p = 2 * p + 1;
}
}
else if (2 * p + 1 < l)
{
if (comp_h(p, 2 * p + 1) > 0)
swap_h(p, 2 * p + 1);
p = 2 * p + 1;
}
else
break;
}
return h[l];
}
int dp[30];
int main()
{
int n;
scanf("%d", &n);
int i, j, k;
st[0] = 0;
for (i = 0; i < n; i++)
{
scanf("%s", ss);
for (j = 0; ss[j] != '\0'; j++)
s[st[i] + j] = ss[j];
st[i + 1] = st[i] + j;
}
l = 0;
for (i = 0; i < n; i++)
push(i);
for (i = 0; i < 30; i++)
dp[i] = 0;
for (; l > 0;)
{
i = pop();
k = 0;
for (j = st[i]; j < st[i + 1] - 1; j++)
if (s[j] > s[j + 1])
k++;
if (k > 0)
continue;
k = s[st[i + 1] - 1] - 'a';
for (j = s[st[i]] - 'a'; j >= 0; j--)
if (dp[k] < dp[j] + st[i + 1] - st[i])
dp[k] = dp[j] + st[i + 1] - st[i];
}
int ans = 0;
for (i = 0; i < 30; i++)
if (ans < dp[i])
ans = dp[i];
printf("%d\n", ans);
return 0;
}
pengin_2000