Created
November 11, 2012 13:48
-
-
Save orisano/4054940 to your computer and use it in GitHub Desktop.
PCK本戦2問目:後になって書いてみた編
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define LIMIT (10000) | |
int main(void) | |
{ | |
int n; | |
int mem[2][10000]; | |
int ct; | |
int under_line; | |
int dl; | |
int i, j; | |
int index; | |
while (scanf("%d", &n), n){ | |
for (i = 0; i < n; i++){ | |
scanf("%d", &mem[0][i]); | |
} | |
under_line = n; | |
for (ct = 0; ct < LIMIT; ct++){ | |
for (i = 0; i < under_line && mem[ct & 1][i] == i + 1; i++); | |
if (i == under_line) break; | |
dl = index = 0; | |
for (i = 0; i < under_line; i++){ | |
dl -= !(--mem[ct & 1][i]); | |
if (mem[ct & 1][i]) mem[!(ct & 1)][index++] = mem[ct & 1][i]; | |
} | |
mem[!(ct & 1)][index] = under_line; | |
under_line = under_line + 1 + dl; | |
} | |
printf("%d\n", ct != LIMIT ? ct : -1); | |
} | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment