Submission #67031315
Source Code Expand
Copy
#include <stdio.h>int N;char S[114514];int main(void) {int T, tc;if (scanf("%d", &T) != 1) return 1;for (tc = 0; tc < T; tc++) {int i;int nuki = -1;if (scanf("%d", &N) != 1) return 1;if (scanf("%114513s", S) != 1) return 1;for (i = 1; i < N; i++) {if (S[i - 1] > S[i]) {nuki = i - 1;break;}}if (nuki < 0) {/* 長さ1の連続部分文字列を選ぶ → 変わらない */
#include <stdio.h> int N; char S[114514]; int main(void) { int T, tc; if (scanf("%d", &T) != 1) return 1; for (tc = 0; tc < T; tc++) { int i; int nuki = -1; if (scanf("%d", &N) != 1) return 1; if (scanf("%114513s", S) != 1) return 1; for (i = 1; i < N; i++) { if (S[i - 1] > S[i]) { nuki = i - 1; break; } } if (nuki < 0) { /* 長さ1の連続部分文字列を選ぶ → 変わらない */ puts(S); } else { int ire = -1; for (i = nuki + 1; i < N; i++) { if (S[nuki] < S[i]) { ire = i; break; } } for (i = 0; i < N; i++) { if (i == ire) putchar(S[nuki]); if (i != nuki) putchar(S[i]); } if (ire < 0) putchar(S[nuki]); putchar('\n'); } } return 0; } /* ポイント:辞書順は、後ろがどうなろうと、前で勝ってしまえば勝ち 最初に1文字抜いたほうが有利になるところで抜く → その後、最初に抜いた文字を入れたほうが有利になるところで入れる */
Submission Info
Submission Time | |
---|---|
Task | D - String Rotation |
User | mikecat |
Language | C (gcc 12.2.0) |
Score | 400 |
Code Size | 1061 Byte |
Status | AC |
Exec Time | 3 ms |
Memory | 1748 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_01.txt |
All | 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 1 ms | 1516 KiB |
01_test_01.txt | AC | 3 ms | 1644 KiB |
01_test_02.txt | AC | 3 ms | 1604 KiB |
01_test_03.txt | AC | 3 ms | 1616 KiB |
01_test_04.txt | AC | 3 ms | 1580 KiB |
01_test_05.txt | AC | 1 ms | 1620 KiB |
01_test_06.txt | AC | 1 ms | 1592 KiB |
01_test_07.txt | AC | 1 ms | 1628 KiB |
01_test_08.txt | AC | 1 ms | 1580 KiB |
01_test_09.txt | AC | 1 ms | 1536 KiB |
01_test_10.txt | AC | 1 ms | 1652 KiB |
01_test_11.txt | AC | 1 ms | 1680 KiB |
01_test_12.txt | AC | 1 ms | 1616 KiB |
01_test_13.txt | AC | 1 ms | 1640 KiB |
01_test_14.txt | AC | 1 ms | 1660 KiB |
01_test_15.txt | AC | 1 ms | 1688 KiB |
01_test_16.txt | AC | 1 ms | 1748 KiB |
01_test_17.txt | AC | 2 ms | 1604 KiB |