@@ -1122,27 +1122,46 @@ public function addAction(Request $request): Response
1122
1122
1123
1123
/**
1124
1124
* @param Testcase[] $testcases
1125
+ *
1126
+ * Assumes testcases are in order of their rank.
1125
1127
*/
1126
1128
private function addTestcasesToZip (array $ testcases , ZipArchive $ zip , bool $ isSample ): void
1127
1129
{
1130
+
1131
+ // Verify whether order of original filenames matches order of testcases by rank.
1132
+ // If so, prefer their original name, otherwise replace the name with the rank to ensure same order.
1133
+ $ prev = null ;
1134
+ $ isStillSorted = true ;
1135
+ foreach ($ testcases as $ testcase ) {
1136
+ if ($ prev !== null && $ prev >= $ testcase ->getOrigInputFilename ()) {
1137
+ $ isStillSorted = false ;
1138
+ break ;
1139
+ }
1140
+ $ prev = $ testcase ->getOrigInputFilename ();
1141
+ }
1142
+
1128
1143
$ formatString = sprintf ('data/%%s/%%0%dd ' , ceil (log10 (count ($ testcases ) + 1 )));
1129
1144
$ rankInGroup = 0 ;
1130
1145
foreach ($ testcases as $ testcase ) {
1131
1146
$ rankInGroup ++;
1132
- $ filename = sprintf ($ formatString , $ isSample ? 'sample ' : 'secret ' , $ rankInGroup );
1133
- $ zip ->addFromString ($ filename . '.in ' , $ testcase ->getContent ()->getInput ());
1134
- $ zip ->addFromString ($ filename . '.ans ' , $ testcase ->getContent ()->getOutput ());
1147
+ if ($ isStillSorted ) {
1148
+ $ filenamePrefix = sprintf ("data/%s/%s " , $ isSample ? 'sample ' : 'secret ' , $ testcase ->getOrigInputFilename ());
1149
+ } else {
1150
+ $ filenamePrefix = sprintf ($ formatString , $ isSample ? 'sample ' : 'secret ' , $ rankInGroup );
1151
+ }
1152
+ $ zip ->addFromString ($ filenamePrefix . '.in ' , $ testcase ->getContent ()->getInput ());
1153
+ $ zip ->addFromString ($ filenamePrefix . '.ans ' , $ testcase ->getContent ()->getOutput ());
1135
1154
1136
1155
if (!empty ($ testcase ->getDescription (true ))) {
1137
1156
$ description = $ testcase ->getDescription (true );
1138
1157
if (!str_contains ($ description , "\n" )) {
1139
1158
$ description .= "\n" ;
1140
1159
}
1141
- $ zip ->addFromString ($ filename . '.desc ' , $ description );
1160
+ $ zip ->addFromString ($ filenamePrefix . '.desc ' , $ description );
1142
1161
}
1143
1162
1144
1163
if (!empty ($ testcase ->getImageType ())) {
1145
- $ zip ->addFromString ($ filename . '. ' . $ testcase ->getImageType (),
1164
+ $ zip ->addFromString ($ filenamePrefix . '. ' . $ testcase ->getImageType (),
1146
1165
$ testcase ->getContent ()->getImage ());
1147
1166
}
1148
1167
}
0 commit comments