Skip to content

Commit 281737e

Browse files
committed
Improve montresor task got
1 parent c86476c commit 281737e

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

more/montresor/got/got.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,34 @@ struct Sol {
5757
mem.resize(R*C,NONE);
5858
completed = 0;
5959

60-
queue<pair<sint,sint>> q;
60+
queue<sint> q;
6161
for(sint j=0;j<J;++j){
62-
q.push(pair<sint,sint>(castles[j].i, j));
62+
q.push(castles[j].i);
6363
poles[j].missing = castles[j].size;
64-
}
6564

66-
while(!q.empty()){
67-
sint i,j;
68-
tie(i,j)=q.front();
69-
q.pop();
65+
while(!q.empty()){
66+
sint i=q.front();
67+
q.pop();
7068

71-
if (mem[i] != NONE) continue;
72-
const Castle& castle = castles[j];
73-
if (grid[i] != 0 && grid[i] != castle.size) continue;
74-
Pole& pole = poles[j];
75-
if (pole.missing == 0) continue;
76-
for_neighbors(i, neigh, if (mem[neigh] != NONE && mem[neigh] != j && castles[mem[neigh]].size == castle.size) continue;)
69+
if (mem[i] != NONE) continue;
70+
const Castle& castle = castles[j];
71+
if (grid[i] != 0 && grid[i] != castle.size) continue;
72+
Pole& pole = poles[j];
73+
if (pole.missing == 0) continue;
74+
for_neighbors(i, neigh, if (mem[neigh] != NONE && mem[neigh] != j && castles[mem[neigh]].size == castle.size) continue;)
75+
76+
pole.missing -= 1;
77+
if (pole.missing == 0) {
78+
completed += castle.size;
79+
}
80+
mem[i] = j;
7781

78-
pole.missing -= 1;
79-
if (pole.missing == 0) {
80-
completed += castle.size;
82+
for_neighbors(i, neigh, {
83+
if (mem[neigh] == NONE && pole.missing != 0) {
84+
q.push(neigh);
85+
}
86+
})
8187
}
82-
mem[i] = j;
83-
84-
for_neighbors(i, neigh, {
85-
if (mem[neigh] == NONE && pole.missing != 0) {
86-
q.push(pair<sint,sint>(neigh, j));
87-
}
88-
})
8988
}
9089

9190
// deb("INITIAL!!");
@@ -267,7 +266,7 @@ void setupTimeLimit(){
267266

268267
struct rlimit limit;
269268
getrlimit(RLIMIT_CPU, &limit);
270-
limit.rlim_cur = 1;
269+
limit.rlim_cur = 2;
271270
setrlimit(RLIMIT_CPU, &limit);
272271
}
273272

0 commit comments

Comments
 (0)