Skip to content

Commit 71cbdab

Browse files
243&247&248 submit and 239&241 statement's upd (#69)
* Update problem 211 and 220 * Update problem 239&241 * 243&247&248submit and 239&241 statement's upd * 239 statement upd
1 parent 0e7a5c8 commit 71cbdab

37 files changed

Lines changed: 17929 additions & 2 deletions

algorithmic/problems/239/statement.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Scoring:
2828
Your score is calculated based on the number of edges $m$, and $m_0$(edges by std):
2929
if $m \leq m_0$, you receive full score (1.0).
3030
if $m>3 * m_0$, you receive 0 score.
31-
otherwise Score = $(m - m_0) / (2 * m_0)$, linearly decreasing from 1.0 to 0.0.
31+
otherwise Score = $(3 * m_0 - m) / (2 * m_0)$, linearly decreasing from 1.0 to 0.0.
3232

3333
Time limit:
3434
2 seconds

algorithmic/problems/241/statement.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Scoring:
7373
Your score is calculated based on the number of (&,|) $m$, and $m_0$(number of (&,|) by std):
7474
if $m \leq m_0$, you receive full score (1.0).
7575
if $m>2 * m_0$, you receive 0 score.
76-
otherwise Score = $(m - m_0) / (m_0)$, linearly decreasing from 1.0 to 0.0.
76+
otherwise Score = $(2 * m_0 - m) / (m_0)$, linearly decreasing from 1.0 to 0.0.
7777

7878
Time limit:
7979
2 seconds
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type: interactive
2+
interactor: interactor.cc
3+
time: 15s
4+
memory: 1024m
5+
subtasks:
6+
- score: 100
7+
n_cases: 4
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#include "testlib.h"
2+
#include <iostream>
3+
#include <vector>
4+
#include <string>
5+
#include <algorithm>
6+
7+
using namespace std;
8+
9+
// Directions: 0: N, 1: E, 2: S, 3: W
10+
const int DR[] = {-1, 0, 1, 0};
11+
const int DC[] = {0, 1, 0, -1};
12+
13+
int R, C;
14+
vector<string> grid;
15+
int trueR, trueC, trueDir;
16+
17+
// Check if position (r, c) is valid (within bounds and is empty cell)
18+
bool isValid(int r, int c) {
19+
return r >= 0 && r < R && c >= 0 && c < C && grid[r][c] == '.';
20+
}
21+
22+
// Calculate distance to wall in the given direction
23+
int getDistanceToWall(int r, int c, int dir) {
24+
int dist = 0;
25+
int nr = r + DR[dir];
26+
int nc = c + DC[dir];
27+
while (isValid(nr, nc)) {
28+
dist++;
29+
nr += DR[dir];
30+
nc += DC[dir];
31+
}
32+
return dist;
33+
}
34+
35+
int main(int argc, char* argv[]) {
36+
registerInteraction(argc, argv);
37+
38+
// Read input
39+
R = inf.readInt();
40+
C = inf.readInt();
41+
inf.readEoln(); // Skip end of line
42+
43+
grid.resize(R);
44+
for (int i = 0; i < R; i++) {
45+
grid[i] = inf.readToken();
46+
}
47+
48+
trueR = inf.readInt() - 1; // Convert to 0-based index
49+
trueC = inf.readInt() - 1; // Convert to 0-based index
50+
trueDir = inf.readInt();
51+
52+
// Validate hidden start position
53+
if (!isValid(trueR, trueC)) {
54+
quitf(_fail, "Hidden start position (%d, %d) is invalid!", trueR + 1, trueC + 1);
55+
}
56+
57+
// Read standard answer
58+
string res = ans.readToken(); // "yes" or "no"
59+
int stdSteps = ans.readInt(); // Standard number of steps
60+
61+
// Output initial grid to participant
62+
cout << R << " " << C << endl;
63+
for (int i = 0; i < R; i++) {
64+
cout << grid[i] << endl;
65+
}
66+
cout.flush();
67+
68+
// Initialize current position and direction
69+
int curR = trueR;
70+
int curC = trueC;
71+
int curDir = trueDir;
72+
73+
// Participant's step counter
74+
int userSteps = 0;
75+
76+
// Interaction loop: allow up to 2 * stdSteps steps
77+
while (userSteps <= 2 * stdSteps) {
78+
// Output distance to wall in current direction
79+
cout << getDistanceToWall(curR, curC, curDir) << endl;
80+
cout.flush();
81+
82+
// Read participant's command
83+
string cmd = ouf.readToken();
84+
userSteps++; // Each command counts as one step (including final "yes"/"no")
85+
86+
if (cmd == "left") {
87+
// Turn left (counterclockwise)
88+
curDir = (curDir + 3) % 4;
89+
} else if (cmd == "right") {
90+
// Turn right (clockwise)
91+
curDir = (curDir + 1) % 4;
92+
} else if (cmd == "step") {
93+
// Move one step forward
94+
int nr = curR + DR[curDir];
95+
int nc = curC + DC[curDir];
96+
if (!isValid(nr, nc)) {
97+
// Crashed into wall
98+
cout << -1 << endl;
99+
cout.flush();
100+
double score_ratio = 0.0;
101+
double unbounded_ratio = 0.0;
102+
quitp(score_ratio, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. Round %d: Crashed into wall at (%d, %d)",
103+
userSteps, score_ratio, unbounded_ratio, userSteps, curR + 1, curC + 1);
104+
}
105+
curR = nr;
106+
curC = nc;
107+
} else if (cmd == "yes" || cmd == "no") {
108+
// Participant claims to have found the position or determined it's impossible
109+
// Calculate score based on number of steps
110+
// Ensure denominator is not zero (handle edge case where stdSteps is 0)
111+
if (stdSteps <= 0) stdSteps = 1;
112+
113+
double score_ratio = 0.0;
114+
double unbounded_ratio = 0.0;
115+
string msg;
116+
117+
if (userSteps <= stdSteps) {
118+
score_ratio = 1.0; // Perfect or better than standard
119+
unbounded_ratio = 1.0;
120+
msg = "Perfect!";
121+
} else if (userSteps >= 2 * stdSteps) {
122+
score_ratio = 0.0; // Too slow
123+
unbounded_ratio = 0.0;
124+
msg = "Too slow.";
125+
} else {
126+
// Linear interpolation: score decreases from 1.0 to 0.0 as steps increase from stdSteps to 2*stdSteps
127+
// Formula: (2*stdSteps - userSteps) / stdSteps
128+
score_ratio = (double)(2 * stdSteps - userSteps) / (double)stdSteps;
129+
unbounded_ratio = score_ratio;
130+
msg = "Suboptimal.";
131+
}
132+
133+
// Ensure score is in [0.0, 1.0]
134+
score_ratio = max(0.0, min(1.0, score_ratio));
135+
unbounded_ratio = max(0.0, min(1.0, unbounded_ratio));
136+
137+
if (cmd == "yes") {
138+
// Participant claims solution exists, read guessed position
139+
int guessR = ouf.readInt();
140+
int guessC = ouf.readInt();
141+
142+
cout << -1 << endl;
143+
cout.flush();
144+
145+
if (res != "yes") {
146+
// Standard answer says "no" but participant says "yes"
147+
double error_score = 0.0;
148+
double error_unbounded = 0.0;
149+
quitp(error_score, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. Standard answer is 'no' but you output 'yes'.",
150+
userSteps, error_score, error_unbounded);
151+
} else if (guessR - 1 == curR && guessC - 1 == curC) {
152+
// Correct guess
153+
quitp(score_ratio, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. %s UserSteps=%d, StdSteps=%d",
154+
userSteps, score_ratio, unbounded_ratio, msg.c_str(), userSteps, stdSteps);
155+
} else {
156+
// Wrong position guessed
157+
double error_score = 0.0;
158+
double error_unbounded = 0.0;
159+
quitp(error_score, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. Wrong position guessed. At (%d, %d), guessed (%d, %d)",
160+
userSteps, error_score, error_unbounded, curR + 1, curC + 1, guessR, guessC);
161+
}
162+
} else if (cmd == "no") {
163+
// Participant claims no solution exists
164+
cout << -1 << endl;
165+
cout.flush();
166+
167+
if (res != "no") {
168+
// Standard answer says "yes" but participant says "no"
169+
double error_score = 0.0;
170+
double error_unbounded = 0.0;
171+
quitp(error_score, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. Standard answer is 'yes' but you output 'no'.",
172+
userSteps, error_score, error_unbounded);
173+
} else {
174+
// Correct: no solution exists
175+
quitp(score_ratio, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. %s UserSteps=%d, StdSteps=%d",
176+
userSteps, score_ratio, unbounded_ratio, msg.c_str(), userSteps, stdSteps);
177+
}
178+
}
179+
} else {
180+
// Invalid command
181+
cout << -1 << endl;
182+
cout.flush();
183+
double score_ratio = 0.0;
184+
double unbounded_ratio = 0.0;
185+
quitp(score_ratio, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. Invalid command: %s",
186+
userSteps, score_ratio, unbounded_ratio, cmd.c_str());
187+
}
188+
}
189+
190+
// Exceeded maximum allowed steps
191+
cout << -1 << endl;
192+
cout.flush();
193+
double score_ratio = 0.0;
194+
double unbounded_ratio = 0.0;
195+
quitp(score_ratio, "Value: %d. Ratio: %.4f, RatioUnbounded: %.4f. Exceeded maximum allowed steps (2 * StdSteps = %d)",
196+
userSteps, score_ratio, unbounded_ratio, 2 * stdSteps);
197+
198+
return 0;
199+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
You are given a map of an area consisting of unit squares, where each square is either open or occupied by a wall.
2+
At the beginning, you are placed in one of the open unit squares, but you do not know which square it is or what direction you face.
3+
Any two individual open spaces are indistinguishable, and likewise for walls. You may walk around the area, at each step observing the distance to the next wall in the direction you face.
4+
The goal is to determine your exact position on the map.
5+
6+
InteractionThe first line of input contains two integers $r$ and $c$ ($1 \le r, c \le 100$) specifying the size of the map.
7+
This is followed by $r$ lines, each containing $c$ characters. Each of these characters is either a dot (.) denoting an open square, or a number sign (#) denoting a square occupied by a wall.
8+
At least one of the squares is open. You know you start in one of the open squares on the map, facing one of the four cardinal directions, but your position and direction are not given in the input.
9+
All squares outside the map area are considered walls.
10+
11+
Interaction then proceeds in rounds. In each round, one line becomes available, containing a single integer $d$ ($0 \le d \le 99$) indicating that you see a wall in front of you at distance $d$.
12+
If the input is -1, the program should terminate immediately
13+
This means there are exactly $d$ open squares between your square and the closest wall in the current direction.
14+
You should then output a line containing one of the following:
15+
"left" to turn 90 degrees to the left,
16+
"right" to turn 90 degrees to the right,
17+
"step" to move one square forward in your current direction,
18+
"yes i j" to claim that your current position is row $i$, column $j$ ($1 \le i \le r$, $1 \le j \le c$),
19+
"no" to claim that no matter what you do, it will not be possible to reliably determine your position.
20+
If you output yes or no, interaction stops and your program should terminate. Otherwise, a new interaction round begins.
21+
22+
Constraint: In order to be accepted, your solution must never step into a wall, and you must minimize the number of interaction rounds used to determine your position (or to conclude that it is impossible).
23+
24+
Example 1:
25+
Input:
26+
3 3
27+
##.
28+
#..
29+
...
30+
31+
Output:
32+
interactor: 1
33+
user: right
34+
interactor: 1
35+
user: step
36+
interator: 0
37+
user: left
38+
interator: 0
39+
user: right
40+
interator: 0
41+
user: right
42+
interator: 1
43+
user: yes 2 2
44+
45+
Scoring:
46+
Your score is determined by the number of interaction rounds your solution requires compared to the standard solution.
47+
Let $C_{user}$ be the number of interaction rounds used by your solution, and $C_{std}$ be the number of interaction rounds used by the standard solution.
48+
The score is calculated as follows:
49+
If $C_{user} > 2 \cdot C_{std}$, you receive 0 points.
50+
If $C_{std} \le C_{user} \le 2 \cdot C_{std}$, your score decreases linearly from the maximum score to 0.
51+
The fraction of points awarded is calculated using the formula:
52+
$$Score = \max\left(0, \frac{2 \cdot C_{std} - C_{user}}{C_{std}}\right) \times MaxPoints$$
53+
This means that matching the standard solution grants 100% of the points, while using exactly twice as many operations results in 0 points.
54+
55+
Time limit:
56+
15 seconds
57+
58+
Memory limit:
59+
1024 MB
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
no
2+
599
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 100
2+
....................................................................................................
3+
1 2 1
4+
off
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yes
2+
40786

0 commit comments

Comments
 (0)