publish frontier_cs (reconvert) (part 20)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- frontier_cs/problems/27/testdata/8.ans +0 -0
- frontier_cs/problems/27/testdata/8.in +1 -0
- frontier_cs/problems/27/testdata/9.ans +0 -0
- frontier_cs/problems/27/testdata/9.in +1 -0
- frontier_cs/problems/28/config.yaml +8 -0
- frontier_cs/problems/28/interactor.cc +106 -0
- frontier_cs/problems/28/statement.txt +60 -0
- frontier_cs/problems/28/testdata/1.ans +1 -0
- frontier_cs/problems/28/testdata/1.in +3 -0
- frontier_cs/problems/28/testdata/10.ans +1 -0
- frontier_cs/problems/28/testdata/10.in +3 -0
- frontier_cs/problems/28/testdata/2.ans +1 -0
- frontier_cs/problems/28/testdata/2.in +3 -0
- frontier_cs/problems/28/testdata/3.ans +1 -0
- frontier_cs/problems/28/testdata/3.in +3 -0
- frontier_cs/problems/28/testdata/4.ans +1 -0
- frontier_cs/problems/28/testdata/4.in +3 -0
- frontier_cs/problems/28/testdata/5.ans +1 -0
- frontier_cs/problems/28/testdata/5.in +3 -0
- frontier_cs/problems/28/testdata/6.ans +1 -0
- frontier_cs/problems/28/testdata/6.in +3 -0
- frontier_cs/problems/28/testdata/7.ans +1 -0
- frontier_cs/problems/28/testdata/7.in +3 -0
- frontier_cs/problems/28/testdata/8.ans +1 -0
- frontier_cs/problems/28/testdata/8.in +3 -0
- frontier_cs/problems/28/testdata/9.ans +1 -0
- frontier_cs/problems/28/testdata/9.in +3 -0
- frontier_cs/problems/3/config.yaml +8 -0
- frontier_cs/problems/3/interactor.cc +121 -0
- frontier_cs/problems/3/statement.txt +69 -0
- frontier_cs/problems/3/testdata/1.ans +1 -0
- frontier_cs/problems/3/testdata/1.in +1 -0
- frontier_cs/problems/3/testdata/10.ans +0 -0
- frontier_cs/problems/3/testdata/10.in +1 -0
- frontier_cs/problems/3/testdata/11.ans +0 -0
- frontier_cs/problems/3/testdata/11.in +1 -0
- frontier_cs/problems/3/testdata/12.ans +0 -0
- frontier_cs/problems/3/testdata/12.in +1 -0
- frontier_cs/problems/3/testdata/13.ans +0 -0
- frontier_cs/problems/3/testdata/13.in +1 -0
- frontier_cs/problems/3/testdata/14.ans +0 -0
- frontier_cs/problems/3/testdata/14.in +1 -0
- frontier_cs/problems/3/testdata/15.ans +0 -0
- frontier_cs/problems/3/testdata/15.in +1 -0
- frontier_cs/problems/3/testdata/16.ans +0 -0
- frontier_cs/problems/3/testdata/16.in +1 -0
- frontier_cs/problems/3/testdata/17.ans +0 -0
- frontier_cs/problems/3/testdata/17.in +1 -0
- frontier_cs/problems/3/testdata/18.ans +0 -0
- frontier_cs/problems/3/testdata/18.in +1 -0
frontier_cs/problems/27/testdata/8.ans
ADDED
|
File without changes
|
frontier_cs/problems/27/testdata/8.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
30 30
|
frontier_cs/problems/27/testdata/9.ans
ADDED
|
File without changes
|
frontier_cs/problems/27/testdata/9.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
200 500
|
frontier_cs/problems/28/config.yaml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
type: interactive
|
| 2 |
+
time: 1s
|
| 3 |
+
memory: 512m
|
| 4 |
+
subtasks:
|
| 5 |
+
- score: 100
|
| 6 |
+
n_cases: 10
|
| 7 |
+
interactor: interactor.cc
|
| 8 |
+
checker_type: testlib
|
frontier_cs/problems/28/interactor.cc
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "testlib.h"
|
| 2 |
+
#include <iostream>
|
| 3 |
+
#include <vector>
|
| 4 |
+
#include <algorithm>
|
| 5 |
+
#include <string>
|
| 6 |
+
#include <map>
|
| 7 |
+
|
| 8 |
+
using namespace std;
|
| 9 |
+
|
| 10 |
+
string s[30][1010];
|
| 11 |
+
char current[15];
|
| 12 |
+
int num[30];
|
| 13 |
+
int cnt = 0;
|
| 14 |
+
map<string, int>vis;
|
| 15 |
+
|
| 16 |
+
void dfs(int now, int start){
|
| 17 |
+
if(cnt >= 1000)return;
|
| 18 |
+
if(now >= 10){
|
| 19 |
+
cnt++;
|
| 20 |
+
for(int i = 0; i < 10; i++){
|
| 21 |
+
s[start][cnt] += current[i];
|
| 22 |
+
}
|
| 23 |
+
return;
|
| 24 |
+
}
|
| 25 |
+
if(now == 0){
|
| 26 |
+
current[now] = (char)('a'+start);
|
| 27 |
+
dfs(now+1, start);
|
| 28 |
+
}
|
| 29 |
+
else{
|
| 30 |
+
for(int i = 0; i < 26; i++){
|
| 31 |
+
current[now] = (char)('a'+i);
|
| 32 |
+
dfs(now+1, start);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
int main(int argc, char *argv[]) {
|
| 38 |
+
/*
|
| 39 |
+
* inf: input
|
| 40 |
+
* ouf: contestant output
|
| 41 |
+
* ans: standard output
|
| 42 |
+
*/
|
| 43 |
+
registerInteraction(argc, argv);
|
| 44 |
+
|
| 45 |
+
for(int i = 0; i < 26; i++){
|
| 46 |
+
cnt = 0;
|
| 47 |
+
dfs(0, i);
|
| 48 |
+
}
|
| 49 |
+
int t = inf.readInt(), n = inf.readInt();
|
| 50 |
+
for(int i = 0; i < 26; i++){
|
| 51 |
+
num[i] = inf.readInt();
|
| 52 |
+
}
|
| 53 |
+
cout<<t<<endl;
|
| 54 |
+
cout.flush();
|
| 55 |
+
cout<<n<<endl;
|
| 56 |
+
cout.flush();
|
| 57 |
+
int sumk = 0;
|
| 58 |
+
for(int i = 1; i <= 4000; i++){
|
| 59 |
+
string operation = ouf.readWord();
|
| 60 |
+
if(operation == "query"){
|
| 61 |
+
string qs = ouf.readWord();
|
| 62 |
+
if(qs.length() >= 10)quitf(_wa, "Invalid query");
|
| 63 |
+
int k = ouf.readInt(1, n);
|
| 64 |
+
sumk += k;
|
| 65 |
+
int start = qs[0]-'a';
|
| 66 |
+
|
| 67 |
+
int match_cnt = 0;
|
| 68 |
+
string ret[1010];
|
| 69 |
+
for(int j = 1; j <= num[start]; j++){
|
| 70 |
+
int match = 1;
|
| 71 |
+
for(int t = 0; t < qs.length(); t++){
|
| 72 |
+
if(s[start][j][t] != qs[t])match = 0;
|
| 73 |
+
}
|
| 74 |
+
if(match){
|
| 75 |
+
match_cnt++;
|
| 76 |
+
ret[match_cnt] = s[start][j];
|
| 77 |
+
if(match_cnt == k)break;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
cout<<match_cnt<<" ";
|
| 81 |
+
for(int j = 1; j <= match_cnt; j++){
|
| 82 |
+
cout<<ret[j]<<" ";
|
| 83 |
+
}
|
| 84 |
+
cout<<endl;
|
| 85 |
+
cout.flush();
|
| 86 |
+
}
|
| 87 |
+
else if(operation == "answer"){
|
| 88 |
+
for(int j = 1; j <= n; j++){
|
| 89 |
+
string answers = ouf.readWord();
|
| 90 |
+
int start = answers[0]-'a';
|
| 91 |
+
if(answers > s[start][num[start]])quitf(_wa, "Invalid answer");
|
| 92 |
+
if(vis[answers])quitf(_wa, "Repeated answer");
|
| 93 |
+
vis[answers] = 1;
|
| 94 |
+
}
|
| 95 |
+
double score = (4000.0-1.0*sumk)/(4000.0-2400.0);
|
| 96 |
+
double unbounded_score = max(0.0, score);
|
| 97 |
+
score = min(score, 1.0);
|
| 98 |
+
score = max(score, 0.0);
|
| 99 |
+
quitp(score, "Ratio: %.3lf, RatioUnbounded: %.3lf", score, unbounded_score);
|
| 100 |
+
}
|
| 101 |
+
else{
|
| 102 |
+
quitf(_wa, "Invalid operation");
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
quitf(_wa, "Too many queries");
|
| 106 |
+
}
|
frontier_cs/problems/28/statement.txt
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Hacking the Project
|
| 2 |
+
Input file: standard input
|
| 3 |
+
Output file: standard output
|
| 4 |
+
Time limit: 1 second
|
| 5 |
+
Memory limit: 512 mebibytes
|
| 6 |
+
This is an interactive problem.
|
| 7 |
+
Lewis is one of the developers of the new programming language called DiverC. The main feature of the
|
| 8 |
+
program written in this language is that the code consists of pairwise distinct words. The compiler of
|
| 9 |
+
DiverC developed by Lewis is, of course, written in DiverC and consists ofN pairwise distinct words.
|
| 10 |
+
Lewis is using the DiverC online autofill service. But Lewis has made one serious mistake: he forgot to
|
| 11 |
+
switch the “use my data for the improvement of the service database” function off. And Lewis was the
|
| 12 |
+
first person who registered on this service, so now the service contains only the words from his compiler.
|
| 13 |
+
Hacker Fernando wants to know all the words Lewis used in the compiler. So he registered at the DiverC
|
| 14 |
+
online autofill service (wisely switching the dangerous function off), and now, for each prefixS and integer
|
| 15 |
+
K entered by Fernando, the service returns, in lexicographic order, the firstK words from Lewis’s code
|
| 16 |
+
that begin with the prefixS. If there are onlyk < Kwords, the service gives out onlyk words (but the
|
| 17 |
+
service usage counter increases byK even in this case).
|
| 18 |
+
Fernando checked the scripts used for the online service and found that one user is limited with the total value ofK in all queries. He wants to determine allN words used by Lewis with several queries
|
| 19 |
+
such as the sum ofK in those queries is as less as possible.
|
| 20 |
+
Can you help him?
|
| 21 |
+
Interaction Protocol
|
| 22 |
+
In the beginning, your program shall read one integerT /emdash.cyr the number of the test cases to be processed
|
| 23 |
+
(1 ≤T ≤5).
|
| 24 |
+
At the beginning of each test case, the jury program tells one integerN /emdash.cyr the number of the words in
|
| 25 |
+
Lewis’s DiverC compiler (1 ≤N ≤1 000).
|
| 26 |
+
Your program can then make two types of requests:
|
| 27 |
+
• query S K /emdash.cyr getK (1 ≤ K ≤ N) lexicographically minimal words starting with prefix S
|
| 28 |
+
(1 ≤|S|≤ 10). If the dictionary contains onlyk such words, where k < K, the answer to the
|
| 29 |
+
query will containk words. The response to the query will be one line of the formkS1S2 . . . Sk,
|
| 30 |
+
where k is the number of the words (0 ≤k ≤K), and thenk words Si in lexicographic order follow.
|
| 31 |
+
• answer S1 S2 ...SN /emdash.cyr tell the full Lewis’s dictionary. After the wordanswer you shall print allN
|
| 32 |
+
words in an arbitrary order separated by spaces. There will be no response from the jury program
|
| 33 |
+
to this request, and your program must then continue with the next test case or exit if the current
|
| 34 |
+
test case was the last one.
|
| 35 |
+
The words in Lewis’s code are composed of lowercase English letters. The length of words is between 1
|
| 36 |
+
to 10 characters. All words in Lewis’s code are pairwise distinct.
|
| 37 |
+
The sum ofK for all queries of the first type for each test should be as less as possible. Your score will be determined by the number of this value. If this value is smaller, you will get a higher score if your final answer is correct.
|
| 38 |
+
If value is greater than 4000, the solution will get 0 points.
|
| 39 |
+
Violating the interaction protocol or exceeding the limits for the sum ofK cause the “Wrong answer”
|
| 40 |
+
verdict.
|
| 41 |
+
Make sure you print the newline character after each query and flush the output stream buffer (flush
|
| 42 |
+
languagecommand)aftereachrequest.Otherwise,thesolutionmaygettheidlenesslimitexceededverdict.
|
| 43 |
+
Note that the jury program isadaptive, i.e. the set of Lewis’s words may be generated at the runtime,
|
| 44 |
+
but the set is guaranteed to be consistent with the answers to previous queries.
|
| 45 |
+
Page 1 of 2Example
|
| 46 |
+
standard input standard output
|
| 47 |
+
1
|
| 48 |
+
4
|
| 49 |
+
1 aaa
|
| 50 |
+
2 aaa aba
|
| 51 |
+
1 cxyxy
|
| 52 |
+
0
|
| 53 |
+
1 czzzz
|
| 54 |
+
query a 1
|
| 55 |
+
query a 4
|
| 56 |
+
query c 1
|
| 57 |
+
query cy 1
|
| 58 |
+
query cz 1
|
| 59 |
+
answer aaa aba czzzz cxyxy
|
| 60 |
+
Page 2 of 2
|
frontier_cs/problems/28/testdata/1.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2
|
frontier_cs/problems/28/testdata/1.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
37 43 97 96 53 78 10 92 13 66 64 81 35 7 0 28 84 49 40 27 0 0 0 0 0 0
|
frontier_cs/problems/28/testdata/10.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
38
|
frontier_cs/problems/28/testdata/10.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
32 2 16 8 128 32 8 16 4 2 8 4 8 16 4 32 1 256 8 8 407 0 0 0 0 0
|
frontier_cs/problems/28/testdata/2.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
24
|
frontier_cs/problems/28/testdata/2.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
24 65 83 73 42 82 65 12 93 92 19 30 5 34 82 14 1 44 3 16 53 39 29 0 0 0
|
frontier_cs/problems/28/testdata/3.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
31
|
frontier_cs/problems/28/testdata/3.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
71 2 56 90 49 7 4 2 86 23 49 95 85 49 85 0 88 14 49 6 21 69 0 0 0 0
|
frontier_cs/problems/28/testdata/4.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
36
|
frontier_cs/problems/28/testdata/4.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
37 43 80 74 7 29 53 18 85 46 64 97 82 17 45 49 72 82 20 0 0 0 0 0 0 0
|
frontier_cs/problems/28/testdata/5.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
68
|
frontier_cs/problems/28/testdata/5.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
34 68 53 83 6 36 65 30 58 61 51 89 15 7 84 2 27 99 61 54 17 0 0 0 0 0
|
frontier_cs/problems/28/testdata/6.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
32
|
frontier_cs/problems/28/testdata/6.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
512 256 128 64 32 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
|
frontier_cs/problems/28/testdata/7.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
60
|
frontier_cs/problems/28/testdata/7.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
512 256 128 64 32 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
frontier_cs/problems/28/testdata/8.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
22
|
frontier_cs/problems/28/testdata/8.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
64 512 2 32 256 134 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
frontier_cs/problems/28/testdata/9.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2
|
frontier_cs/problems/28/testdata/9.in
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
1000
|
| 3 |
+
2 32 4 512 2 16 8 32 128 1 16 64 4 179 0 0 0 0 0 0 0 0 0 0 0 0
|
frontier_cs/problems/3/config.yaml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
type: interactive
|
| 2 |
+
time: 10s
|
| 3 |
+
memory: 1024m
|
| 4 |
+
# A custom checker is required for the special scoring.
|
| 5 |
+
interactor: interactor.cc
|
| 6 |
+
subtasks:
|
| 7 |
+
- score: 100
|
| 8 |
+
n_cases: 20
|
frontier_cs/problems/3/interactor.cc
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "testlib.h"
|
| 2 |
+
#include <vector>
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <cmath>
|
| 5 |
+
|
| 6 |
+
namespace {
|
| 7 |
+
constexpr int MAX_N = (int)1E5 + 10, SINGLE_QUERY_LIM = (int)1E7,
|
| 8 |
+
TOTAL_ROUND_LIM = (int)1E7, TOTAL_QUERY_LIM = (int)3E8;
|
| 9 |
+
int subtask, n;
|
| 10 |
+
int cnt_query, cnt_round;
|
| 11 |
+
int inter[SINGLE_QUERY_LIM+10];
|
| 12 |
+
|
| 13 |
+
// Helper to ensure conditions and quit if they fail
|
| 14 |
+
void Ensure(bool condition, const char* fail_message) {
|
| 15 |
+
if (!condition){
|
| 16 |
+
quitf(_wa, fail_message);
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
int p[MAX_N], q[MAX_N], vis[MAX_N], an;
|
| 21 |
+
|
| 22 |
+
int flip(int u) {
|
| 23 |
+
u = q[u];
|
| 24 |
+
if (vis[u] ^= 1) {
|
| 25 |
+
an += vis[u - 1] + vis[u + 1];
|
| 26 |
+
} else {
|
| 27 |
+
an -= vis[u - 1] + vis[u + 1];
|
| 28 |
+
}
|
| 29 |
+
return an || (vis[1] && vis[n]);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
bool check(int c1[], int c2[]) {
|
| 33 |
+
int opt = -1;
|
| 34 |
+
for (int i = 0; i < n; i++)
|
| 35 |
+
if (c1[i] == c2[0]) {
|
| 36 |
+
opt = i;
|
| 37 |
+
break;
|
| 38 |
+
}
|
| 39 |
+
if (opt == -1) return false;
|
| 40 |
+
|
| 41 |
+
bool f1 = true, f2 = true;
|
| 42 |
+
for (int i = 1, op1 = opt, op2 = opt; i < n; i++) {
|
| 43 |
+
op1++; op2--;
|
| 44 |
+
if (op1 >= n) op1 -= n;
|
| 45 |
+
if (op2 < 0) op2 += n;
|
| 46 |
+
if (c1[op1] != c2[i]) f1 = false;
|
| 47 |
+
if (c1[op2] != c2[i]) f2 = false;
|
| 48 |
+
if ((!f1) && (!f2)) return false;
|
| 49 |
+
}
|
| 50 |
+
return true;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
double f(double x) {
|
| 54 |
+
return std::min(std::max(std::log2(x), 0.0), 8.0);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
double lambda(int t, int Q) {
|
| 58 |
+
return std::max(0.0, 1 - 0.1 * (f(t / 18.0) + f(Q / 1.5E7)));
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
} // namespace
|
| 62 |
+
|
| 63 |
+
void input_inter(int N){
|
| 64 |
+
for(int i = 0; i < N; i++)
|
| 65 |
+
inter[i] = ouf.readInt();
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
void output_inter(const int N){
|
| 69 |
+
std::vector<int> temp_vec;
|
| 70 |
+
for (int i=0; i<N; ++i) temp_vec.push_back(inter[i]);
|
| 71 |
+
println(temp_vec);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
void query(const int N) {
|
| 75 |
+
for (int i = 0; i < N; i++) {
|
| 76 |
+
int u = inter[i];
|
| 77 |
+
Ensure(1 <= u && u <= n, "Query value out of range [1, n]");
|
| 78 |
+
inter[i] = flip(u);
|
| 79 |
+
}
|
| 80 |
+
output_inter(N);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
int main(int argc, char* argv[]) {
|
| 84 |
+
registerInteraction(argc, argv);
|
| 85 |
+
subtask = inf.readInt();
|
| 86 |
+
n = inf.readInt();
|
| 87 |
+
for (int i = 0; i < n; i++) {
|
| 88 |
+
p[i] = ans.readInt();
|
| 89 |
+
q[p[i]] = i + 1;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
inter[0] = subtask;
|
| 93 |
+
inter[1] = n;
|
| 94 |
+
output_inter(2);
|
| 95 |
+
|
| 96 |
+
int N;
|
| 97 |
+
while (true) {
|
| 98 |
+
N = ouf.readInt();
|
| 99 |
+
if (N == -1) {
|
| 100 |
+
input_inter(n);
|
| 101 |
+
Ensure(check(p, inter), "Final answer is incorrect.");
|
| 102 |
+
break;
|
| 103 |
+
} else {
|
| 104 |
+
Ensure(N <= SINGLE_QUERY_LIM, "Single query size limit exceeded.");
|
| 105 |
+
cnt_round += 1;
|
| 106 |
+
cnt_query += N;
|
| 107 |
+
Ensure(cnt_round <= TOTAL_ROUND_LIM, "Total round limit exceeded.");
|
| 108 |
+
Ensure(cnt_query <= TOTAL_QUERY_LIM, "Total query limit exceeded.");
|
| 109 |
+
input_inter(N);
|
| 110 |
+
query(N);
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
double score_ratio = lambda(cnt_round, cnt_query);
|
| 115 |
+
|
| 116 |
+
// Use quitp with a formatted message that includes the "Ratio:" tag
|
| 117 |
+
quitp(score_ratio, "Correct. Rounds: %d, Queries: %d. Ratio: %.4f", cnt_round, cnt_query, score_ratio);
|
| 118 |
+
|
| 119 |
+
return 0;
|
| 120 |
+
}
|
| 121 |
+
|
frontier_cs/problems/3/statement.txt
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This is an interactive question.
|
| 2 |
+
|
| 3 |
+
time limit: 10 seconds (up to 5 seconds for interactive library)
|
| 4 |
+
Space limitations: 1GB (up to 64MB for interactive library)
|
| 5 |
+
|
| 6 |
+
Description
|
| 7 |
+
Hope City is a city built on a floating island. At the edge of the floating island, there are n lamp sockets evenly distributed, forming a ring shape. Each lamp holder is labeled with a number between 1 and n, and forms an arrangement of length n in a clockwise direction p1, p2,..., pn. You don't know this arrangement and hope to restore it through interaction with the system.
|
| 8 |
+
|
| 9 |
+
You can ask the system to switch the state of a set of lamp holders at a time (if it was not originally lit, it will be lit; if it was originally lit, it will be extinguished).
|
| 10 |
+
|
| 11 |
+
The system will maintain a set of currently lit lamp holders S (initially empty) internally. You cannot directly see the contents of the set, but you can obtain the following information through interaction:
|
| 12 |
+
|
| 13 |
+
You can submit a set of operations at once (i.e. a series of target IDs for wick input), and the system will process each of these operations one by one:
|
| 14 |
+
|
| 15 |
+
- If a lamp holder is not in S, it will be lit up after inserting the wick (add into S);
|
| 16 |
+
- If a lamp holder is already in S, it will be extinguished up after inserting the wick (remove it from S);
|
| 17 |
+
- After each operation, the system will record whether there is a pair of adjacent lamp holders on the ring in the current set S, and return the records of all operations together.
|
| 18 |
+
After you submit a set of operations at once and receive the returned records, S will not be cleared, but will continue to serve as the initial set for the next set of operations.
|
| 19 |
+
|
| 20 |
+
Input
|
| 21 |
+
One line, contains two integers, subtask, n, representing the subtask ID and the length of the loop;
|
| 22 |
+
|
| 23 |
+
Implementation Details
|
| 24 |
+
To ask a query, output one line. First output a number L followed by a space, then print a sequence of L integers ranging from 1 to n separated by a space.
|
| 25 |
+
After flushing your output, your program should read a sequence of L integers, indicating whether there are adjacent pairs in S after each operation.
|
| 26 |
+
Specifically, The system will maintain a set S, which is initially the result of the previous query (i.e. not reset), and sequentially scans each element u in this query:
|
| 27 |
+
If u is not in S when scanned, perform an operation to light up u so that u is in S; if u is in S when scanned, perform an operation to extinguish u so that u is not in S. Then report an integer indicating whether there are adjacent pairs in S after this operation(0: does not exist; 1: exist).
|
| 28 |
+
|
| 29 |
+
If you want to guess the permutation, output one line. First output -1 followed by a space, then print a permutation of n separated by a space, representing the arrangement of lamp holder numbers p1~pn. Since the ring has no starting point or direction, any cyclic shift of p1~pn or p1~pn is considered correct. After flushing your output, your program should exit immediately.
|
| 30 |
+
|
| 31 |
+
Note that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.
|
| 32 |
+
|
| 33 |
+
To flush your output, you can use:
|
| 34 |
+
fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
|
| 35 |
+
|
| 36 |
+
Subtask
|
| 37 |
+
Subtask 1 (10 points): Ensure n=1000.
|
| 38 |
+
Subtask 2 (90 points): Ensure n=10 ^ 5.
|
| 39 |
+
|
| 40 |
+
For a testcase, if your interaction process is illegal or the returned answer is incorrect, you will directly receive 0 points.
|
| 41 |
+
|
| 42 |
+
Otherwise, record the total number of times you call query as t, and record the sum of the number of operations you perform each time when calling query as Q.
|
| 43 |
+
|
| 44 |
+
Your score ratio lambda will be calculated according to the following formula:
|
| 45 |
+
lambda=max (0, 1-0.1 (f (t/18)+f (Q/ (1.5 * 10^7)))
|
| 46 |
+
Where f (x)=min (max (log_2 (x), 0), 8)
|
| 47 |
+
Then, if the subtask where this testcase is located has a maximum score of S, then you will get lambda * S.
|
| 48 |
+
|
| 49 |
+
The total number of times you call query cannot exceed 10 ^ 7, and the sum of the number of operations you perform each time when calling 'query' cannot exceed 3 * 10 ^ 8.
|
| 50 |
+
To prevent unexpected behavior caused by a large vector, you also need to ensure that the number of operations in a single query call always does not exceed 10 ^ 7.
|
| 51 |
+
|
| 52 |
+
Interactive Example
|
| 53 |
+
Assuming n=4 and the arrangement of lamp holder is [2,4,1,3], the following is a valid interaction process:
|
| 54 |
+
|
| 55 |
+
Player Program | Interaction Library | Description
|
| 56 |
+
- | Call solve (4, 0) | Start the interaction process
|
| 57 |
+
Call query ([1, 2]) | Return [0, 0] | Found that the two lamp holders with numbers 1 and 2 are not adjacent on the ring
|
| 58 |
+
Call query ([1, 2]) | Return [0, 0] | extinguish 1,2
|
| 59 |
+
Call query ([1, 3]) | Return [0, 1] | Found that two lamp holders with numbers 1 and 3 are adjacent on the ring
|
| 60 |
+
Call query ([1, 3]) | Return [0, 0] | extinguish 1,3
|
| 61 |
+
Call query ([1, 4]) | Return [0, 1] | Found that two lamp holders with numbers 1,4 are adjacent on the ring
|
| 62 |
+
Call query ([1, 4]) | Return [0, 0] | extinguish 1,4
|
| 63 |
+
Call query ([2, 3]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 3 are adjacent on the ring
|
| 64 |
+
Call query ([2, 3]) | Return [0, 0] | extinguish 2,3
|
| 65 |
+
Call query ([2, 4]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 4 are adjacent on the ring
|
| 66 |
+
Call query ([2, 4]) | Return [0, 0] | extinguish 2,4
|
| 67 |
+
Call query ([3, 4]) | Return [0, 0] | Found that the two lamp holders with numbers 3 and 4 are not adjacent on the ring
|
| 68 |
+
Call query ([3, 4]) | Return [0, 0] | extinguish 3,4
|
| 69 |
+
Run ends and returns [1, 4, 2, 3] | Print interaction result to screen | Interaction ends, result is correct
|
frontier_cs/problems/3/testdata/1.ans
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3 1 4 2 7 5 8 6 11 9 12 10 15 13 16 14 19 17 20 18 23 21 24 22 27 25 28 26 31 29 32 30 35 33 36 34 39 37 40 38 43 41 44 42 47 45 48 46 51 49 52 50 55 53 56 54 59 57 60 58 63 61 64 62 67 65 68 66 71 69 72 70 75 73 76 74 79 77 80 78 83 81 84 82 87 85 88 86 91 89 92 90 95 93 96 94 99 97 100 98 103 101 104 102 107 105 108 106 111 109 112 110 115 113 116 114 119 117 120 118 123 121 124 122 127 125 128 126 131 129 132 130 135 133 136 134 139 137 140 138 143 141 144 142 147 145 148 146 151 149 152 150 155 153 156 154 159 157 160 158 163 161 164 162 167 165 168 166 171 169 172 170 175 173 176 174 179 177 180 178 183 181 184 182 187 185 188 186 191 189 192 190 195 193 196 194 199 197 200 198 203 201 204 202 207 205 208 206 211 209 212 210 215 213 216 214 219 217 220 218 223 221 224 222 227 225 228 226 231 229 232 230 235 233 236 234 239 237 240 238 243 241 244 242 247 245 248 246 251 249 252 250 255 253 256 254 259 257 260 258 263 261 264 262 267 265 268 266 271 269 272 270 275 273 276 274 279 277 280 278 283 281 284 282 287 285 288 286 291 289 292 290 295 293 296 294 299 297 300 298 303 301 304 302 307 305 308 306 311 309 312 310 315 313 316 314 319 317 320 318 323 321 324 322 327 325 328 326 331 329 332 330 335 333 336 334 339 337 340 338 343 341 344 342 347 345 348 346 351 349 352 350 355 353 356 354 359 357 360 358 363 361 364 362 367 365 368 366 371 369 372 370 375 373 376 374 379 377 380 378 383 381 384 382 387 385 388 386 391 389 392 390 395 393 396 394 399 397 400 398 403 401 404 402 407 405 408 406 411 409 412 410 415 413 416 414 419 417 420 418 423 421 424 422 427 425 428 426 431 429 432 430 435 433 436 434 439 437 440 438 443 441 444 442 447 445 448 446 451 449 452 450 455 453 456 454 459 457 460 458 463 461 464 462 467 465 468 466 471 469 472 470 475 473 476 474 479 477 480 478 483 481 484 482 487 485 488 486 491 489 492 490 495 493 496 494 499 497 500 498 503 501 504 502 507 505 508 506 511 509 512 510 515 513 516 514 519 517 520 518 523 521 524 522 527 525 528 526 531 529 532 530 535 533 536 534 539 537 540 538 543 541 544 542 547 545 548 546 551 549 552 550 555 553 556 554 559 557 560 558 563 561 564 562 567 565 568 566 571 569 572 570 575 573 576 574 579 577 580 578 583 581 584 582 587 585 588 586 591 589 592 590 595 593 596 594 599 597 600 598 603 601 604 602 607 605 608 606 611 609 612 610 615 613 616 614 619 617 620 618 623 621 624 622 627 625 628 626 631 629 632 630 635 633 636 634 639 637 640 638 643 641 644 642 647 645 648 646 651 649 652 650 655 653 656 654 659 657 660 658 663 661 664 662 667 665 668 666 671 669 672 670 675 673 676 674 679 677 680 678 683 681 684 682 687 685 688 686 691 689 692 690 695 693 696 694 699 697 700 698 703 701 704 702 707 705 708 706 711 709 712 710 715 713 716 714 719 717 720 718 723 721 724 722 727 725 728 726 731 729 732 730 735 733 736 734 739 737 740 738 743 741 744 742 747 745 748 746 751 749 752 750 755 753 756 754 759 757 760 758 763 761 764 762 767 765 768 766 771 769 772 770 775 773 776 774 779 777 780 778 783 781 784 782 787 785 788 786 791 789 792 790 795 793 796 794 799 797 800 798 803 801 804 802 807 805 808 806 811 809 812 810 815 813 816 814 819 817 820 818 823 821 824 822 827 825 828 826 831 829 832 830 835 833 836 834 839 837 840 838 843 841 844 842 847 845 848 846 851 849 852 850 855 853 856 854 859 857 860 858 863 861 864 862 867 865 868 866 871 869 872 870 875 873 876 874 879 877 880 878 883 881 884 882 887 885 888 886 891 889 892 890 895 893 896 894 899 897 900 898 903 901 904 902 907 905 908 906 911 909 912 910 915 913 916 914 919 917 920 918 923 921 924 922 927 925 928 926 931 929 932 930 935 933 936 934 939 937 940 938 943 941 944 942 947 945 948 946 951 949 952 950 955 953 956 954 959 957 960 958 963 961 964 962 967 965 968 966 971 969 972 970 975 973 976 974 979 977 980 978 983 981 984 982 987 985 988 986 991 989 992 990 995 993 996 994 999 997 1000 998
|
frontier_cs/problems/3/testdata/1.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
1 1000
|
frontier_cs/problems/3/testdata/10.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/10.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/11.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/11.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/12.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/12.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/13.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/13.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/14.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/14.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/15.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/15.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/16.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/16.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/17.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/17.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|
frontier_cs/problems/3/testdata/18.ans
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontier_cs/problems/3/testdata/18.in
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2 100000
|