# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
815900 |
2023-08-09T02:09:26 Z |
yeyso |
Minerals (JOI19_minerals) |
C++14 |
|
10 ms |
1608 KB |
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int N) {
int a = 0;
int b = 0;
//vector<vector<int>> res(2 * N + 1, vector<int>(15, 0));
if(N > 100){
vector<int> arr(2 * N + 1, 0);
vector<int> res(2 * N + 1, 1);
for(int k = 0; k <= 14; k ++){
for(int i = 0; i <= 2 * N; i ++){
if(k > 0){
if(i & (1 << k)){
if(i & (1 << (k - 1))){} else {
a = Query(i);
arr[i] ^= 1;
}
} else {
if(i & (1 << (k - 1))){
a = Query(i);
arr[i] ^= 1;
}
}
} else {
if(i & (1 << 0)){
a = Query(i);
arr[i] ^= 1;
}
}
//if(not i & (1 << k) and i & (1 << (k - 1))){
// a = Query(i);
//}
}
for(int i = 1; i <= N; i ++){
//cout << arr[i];
b = Query(i);
if(a == b){
// Then b is paired with something where the kth bit is 1
//res[a][k] = 1;
res[i] += (1 << k);
}
b = Query(i);
}
//cout << "\n";
/*for(int i = 1; i <= 2 * N; i ++){
if(i & (1 << k)){
//a = Query(i);
//arr[i] ^= 1;
}
}*/
}
/*
N queries to set up
2N queries for each one
N queries to remove
Repeat all log(n) times
N / 2 queries to set up
4N queries for each one
Repeat log(n) times
= 4N * 15
*/
set<pair<int, int>> ans;
for(int i = 0; i < res.size() / 2 + 1; i ++){
ans.insert({min(i , res[i] -1), max(i , res[i] - 1)});
//Answer(i, res[i]);
}
for(auto itx = ++ans.begin(); itx != ans.end(); ++itx){
Answer((*itx).first, (*itx).second);
//cout << (*itx).first << " " << (*itx).second << "\n";
}
} else {
vector<int> res(2 * N + 1, 1);
for(int k = 0; k < 15; k ++){
for(int i = 1; i <= 2 * N; i ++){
if(i & (1 << k)){
a = Query(i);
}
}
for(int i = 1; i <= 2 * N; i ++){
b = Query(i);
if(a == b){
// Then b is paired with something where the kth bit is 1
//res[a][k] = 1;
res[i] += (1 << k);
}
b = Query(i);
}
for(int i = 1; i <= 2 * N; i ++){
if(i & (1 << k)){
a = Query(i);
}
}
}
set<pair<int, int>> ans;
for(int i = 0; i < res.size(); i ++){
ans.insert({min(i , res[i] -1), max(i , res[i] - 1)});
//Answer(i, res[i]);
}
for(auto itx = ++ans.begin(); itx != ans.end(); ++itx){
Answer((*itx).first, (*itx).second);
//cout << (*itx).first << " " << (*itx).second << "\n";
}
}
}
/*
g++ -std=gnu++17 -O2 -Wall -pipe -static -o minerals grader.cpp minerals.cpp
4
1 5
2 6
3 7
4 8
*/
Compilation message
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 0; i < res.size() / 2 + 1; i ++){
| ~~^~~~~~~~~~~~~~~~~~~~
minerals.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int i = 0; i < res.size(); i ++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
7 ms |
1000 KB |
Output is correct |
5 |
Correct |
10 ms |
1608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
7 ms |
1000 KB |
Output is correct |
9 |
Correct |
10 ms |
1608 KB |
Output is correct |
10 |
Incorrect |
1 ms |
336 KB |
Wrong Answer [6] |
11 |
Halted |
0 ms |
0 KB |
- |