#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
bool are_connected(std::vector<int> A, std::vector<int> B);
void add(vector<int> &a,vector<int> &b){
reverse(a.begin(),a.end());
for(auto i : b)a.push_back(i);
}
vector<int> longest_trip(int N, int D)
{
queue<vector<int>> q;
for(int i=0;i<N;i++){
q.push({i});
}
while(q.size()>2){
auto a = q.front();
q.pop();
auto b = q.front();
q.pop();
auto c = q.front();
q.pop();
if(are_connected({*a.begin()},{*b.begin()})){
;
}else if(are_connected({*a.begin()},{*c.begin()})){
swap(b,c);
}else{
swap(a,c);
}
add(a,b);
q.push(a);
q.push(c);
}
auto a = q.front();
q.pop();
auto b = q.front();
q.pop();
if(a.size()>b.size())return a;
else return b;
}
/*
1
5 1
1
1 1
0 0 1
0 0 0 1
static inline constexpr int maxNumberOfCalls = 32640;
static inline constexpr int maxTotalNumberOfCalls = 150000;
static inline constexpr int maxTotalNumberOfLandmarksInCalls = 1500000;
static int call_counter = 0;
static int total_call_counter = 0;
static int landmark_counter = 0;
static int C, N, D;
static std::vector<std::vector<int>> U;
static std::vector<bool> present;
static inline void protocol_violation(std::string message)
{
printf("Protocol Violation: %s\n", message.c_str());
exit(0);
}
bool are_connected(std::vector<int> A, std::vector<int> B)
{
++call_counter;
++total_call_counter;
if (call_counter > maxNumberOfCalls || total_call_counter > maxTotalNumberOfCalls)
{
protocol_violation("too many calls");
}
int nA = A.size(), nB = B.size();
landmark_counter += nA + nB;
if (landmark_counter > maxTotalNumberOfLandmarksInCalls)
{
protocol_violation("too many elements");
}
if (nA == 0 || nB == 0)
{
protocol_violation("invalid array");
}
for (int i = 0; i < nA; ++i)
{
if (A[i] < 0 || N <= A[i])
{
protocol_violation("invalid array");
}
if (present[A[i]])
{
protocol_violation("invalid array");
}
present[A[i]] = true;
}
for (int i = 0; i < nA; ++i)
{
present[A[i]] = false;
}
for (int i = 0; i < nB; ++i)
{
if (B[i] < 0 || N <= B[i])
{
protocol_violation("invalid array");
}
if (present[B[i]])
{
protocol_violation("invalid array");
}
present[B[i]] = true;
}
for (int i = 0; i < nB; ++i)
{
present[B[i]] = false;
}
for (int i = 0; i < nA; ++i)
{
for (int j = 0; j < nB; ++j)
{
if (A[i] == B[j])
{
protocol_violation("non-disjoint arrays");
}
}
}
for (int i = 0; i < nA; ++i)
{
for (int j = 0; j < nB; ++j)
{
if (U[std::max(A[i], B[j])][std::min(A[i], B[j])] == 1)
{
return true;
}
}
}
return false;
}
int main()
{
assert(1 == scanf("%d", &C));
int maximumCalls = 0;
for (int c = 0; c < C; ++c)
{
call_counter = 0;
assert(2 == scanf("%d %d", &N, &D));
present.assign(N, false);
U.resize(N);
for (int i = 1; i < N; ++i)
{
U[i].resize(i);
for (int j = 0; j < i; ++j)
{
assert(1 == scanf("%d", &U[i][j]));
}
}
for (int i = 2; i < N; ++i)
{
for (int j = 1; j < i; ++j)
{
for (int k = 0; k < j; ++k)
{
if (U[i][j] + U[i][k] + U[j][k] < D)
{
printf("Insufficient Density\n");
exit(0);
}
}
}
}
std::vector<int> t = longest_trip(N, D);
int l = t.size();
printf("%d\n", l);
for (int i = 0; i < l; ++i)
{
printf(i == 0 ? "%d" : " %d", t[i]);
}
printf("\n");
printf("%d chiamate\n", call_counter);
maximumCalls = std::max(maximumCalls, call_counter);
call_counter = 0;
}
printf("%d max chiamate\n", maximumCalls);
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
208 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
12 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
304 KB |
Output is correct |
10 |
Correct |
9 ms |
316 KB |
Output is correct |
11 |
Correct |
9 ms |
208 KB |
Output is correct |
12 |
Correct |
8 ms |
208 KB |
Output is correct |
13 |
Correct |
7 ms |
208 KB |
Output is correct |
14 |
Correct |
9 ms |
208 KB |
Output is correct |
15 |
Correct |
7 ms |
208 KB |
Output is correct |
16 |
Correct |
8 ms |
300 KB |
Output is correct |
17 |
Correct |
12 ms |
208 KB |
Output is correct |
18 |
Correct |
12 ms |
304 KB |
Output is correct |
19 |
Correct |
9 ms |
208 KB |
Output is correct |
20 |
Correct |
12 ms |
308 KB |
Output is correct |
21 |
Correct |
9 ms |
336 KB |
Output is correct |
22 |
Correct |
11 ms |
328 KB |
Output is correct |
23 |
Correct |
8 ms |
328 KB |
Output is correct |
24 |
Correct |
8 ms |
316 KB |
Output is correct |
25 |
Correct |
9 ms |
208 KB |
Output is correct |
26 |
Correct |
11 ms |
208 KB |
Output is correct |
27 |
Correct |
9 ms |
208 KB |
Output is correct |
28 |
Correct |
8 ms |
208 KB |
Output is correct |
29 |
Correct |
10 ms |
208 KB |
Output is correct |
30 |
Correct |
5 ms |
304 KB |
Output is correct |
31 |
Correct |
14 ms |
208 KB |
Output is correct |
32 |
Correct |
13 ms |
208 KB |
Output is correct |
33 |
Correct |
7 ms |
208 KB |
Output is correct |
34 |
Correct |
10 ms |
304 KB |
Output is correct |
35 |
Correct |
11 ms |
308 KB |
Output is correct |
36 |
Correct |
8 ms |
316 KB |
Output is correct |
37 |
Correct |
11 ms |
336 KB |
Output is correct |
38 |
Correct |
14 ms |
316 KB |
Output is correct |
39 |
Correct |
15 ms |
208 KB |
Output is correct |
40 |
Correct |
9 ms |
316 KB |
Output is correct |
41 |
Correct |
15 ms |
320 KB |
Output is correct |
42 |
Correct |
15 ms |
312 KB |
Output is correct |
43 |
Correct |
14 ms |
332 KB |
Output is correct |
44 |
Correct |
13 ms |
336 KB |
Output is correct |
45 |
Correct |
9 ms |
208 KB |
Output is correct |
46 |
Correct |
9 ms |
208 KB |
Output is correct |
47 |
Correct |
11 ms |
208 KB |
Output is correct |
48 |
Correct |
10 ms |
208 KB |
Output is correct |
49 |
Correct |
7 ms |
208 KB |
Output is correct |
50 |
Correct |
10 ms |
308 KB |
Output is correct |
51 |
Correct |
14 ms |
304 KB |
Output is correct |
52 |
Correct |
13 ms |
304 KB |
Output is correct |
53 |
Correct |
11 ms |
208 KB |
Output is correct |
54 |
Correct |
11 ms |
308 KB |
Output is correct |
55 |
Correct |
9 ms |
208 KB |
Output is correct |
56 |
Correct |
7 ms |
324 KB |
Output is correct |
57 |
Correct |
11 ms |
312 KB |
Output is correct |
58 |
Correct |
8 ms |
324 KB |
Output is correct |
59 |
Correct |
18 ms |
308 KB |
Output is correct |
60 |
Correct |
10 ms |
332 KB |
Output is correct |
61 |
Correct |
10 ms |
328 KB |
Output is correct |
62 |
Correct |
14 ms |
208 KB |
Output is correct |
63 |
Correct |
12 ms |
324 KB |
Output is correct |
64 |
Correct |
15 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |