QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#507097 | #9156. 百万富翁 | 251Sec | 15 | 640ms | 103748kb | C++14 | 5.2kb | 2024-08-06 10:46:04 | 2024-08-06 10:46:04 |
Judging History
answer
#include <bits/stdc++.h>
#include "richest.h"
using std::bitset;
using std::cout;
using std::deque;
using std::endl;
using std::greater;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::nth_element;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::string;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
typedef int li;
typedef long double lf;
inline li read(){
li ans = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
f = (ch == '-') ? -1 : 1;
ch = getchar();
}
while(ch <= '9' && ch >= '0'){
ans = ans * 10 + (ch ^ 48);
ch = getchar();
}
return ans * f;
}
vector<int> v1, v2, v3;
li a[2010][2010];
vector<li> rest, rest2;
std::map<pair<li, li>, li> mp;
int richest(li n, li t, li s){
// FILE *out = fopen("www.ww", "w");
// cout << n << " " << t << " " << s << endl;
v1.clear(), v2.clear(), v3.clear(), rest2.clear(), rest.clear(), mp.clear();
memset(a, 0, sizeof a);
if(t == 1){
v1.clear(), v2.clear();
for(li i = 1; i <= n; i++){
for(li j = i + 1; j <= n; j++){
v1.push_back(i - 1);
v2.push_back(j - 1);
}
}
v3 = ask(v1, v2);
li now = 0;
for(li i = 1; i <= n; i++){
for(li j = i + 1; j <= n; j++){
if(v3[now] + 1 == i) a[i][j] = 1;
else a[i][j] = 0;
a[j][i] = !a[i][j];
// fprintf(out, "%d %d %d %d\n", v1[now], v2[now], v3[now] + 1, a[i][j]);
now++;
}
a[i][i] = 1;
}
for(li i = 1; i <= n; i++){
li cnt = 0;
for(li j = 1; j <= n; ++j) cnt += a[i][j];
// fprintf(out, "cnt %d = %d\n", i, cnt);
if(cnt == n){
// fclose(out);
return i - 1;
}
}
}
mp.clear();
// fprintf(out, "?"); fflush(out);
rest.clear();
li cnt = 0;
for(li i = 0; i < n; i++) rest.push_back(i);
for(li i = 1; i <= 12; i++){
// if(i == 10 || i == 12) continue;
if(i == 11 || i == 9 || i == 7) mp.clear();
v1.clear(), v2.clear();
// fprintf(out, "i = %d, size = %d\n", i, (li)rest.size());
for(li j = 0; j < (li)rest.size(); j += 2){
if(j + 1 < (li)rest.size()){
if(i == 12 || i == 10 || i == 8 || i == 6){
rest2.push_back(v3[mp[{rest[j], rest[j + 1]}]]);
// fprintf(out, "winner %d %d = %d(%d)\n", rest[j], rest[j + 1], mp[{rest[j], rest[j + 1]}], v3[mp[{rest[j], rest[j + 1]}]]);
} else{
v1.push_back(rest[j]), v2.push_back(rest[j + 1]);
}
}
}
if(i == 11 || i == 9 || i == 7 || i == 5){
// fprintf(out, "%d %d\n",(li) rest.size(), cnt + (li)v1.size());
for(li j = 0; j < (li)rest.size(); j += 4){
// fprintf(out, "rest %d = %d\n", 0 + j, rest[0 + j]);
// fprintf(out, "rest %d = %d\n", 1 + j, rest[1 + j]);
// fprintf(out, "rest %d = %d\n", 2 + j, rest[2 + j]);
// fprintf(out, "rest %d = %d\n", 3 + j, rest[3 + j]);
if(j + 2 < (li)rest.size()){
v1.push_back(rest[j]), v2.push_back((rest[j + 2]));
mp[{rest[j], rest[j + 2]}] = v1.size() - 1;
// fprintf(out, "mp %d %d = %d\n", rest[j], rest[j + 2], mp[{rest[j], rest[j + 2]}]);
v1.push_back(rest[j + 1]), v2.push_back((rest[j + 2]));
mp[{rest[j + 1], rest[j + 2]}] = v1.size() - 1;
// fprintf(out, "mp %d %d = %d\n", rest[j + 1], rest[j + 2], mp[{rest[j + 1], rest[j + 2]}]);
if(j + 3 < (li)rest.size()){
v1.push_back(rest[j]), v2.push_back((rest[j + 3]));
mp[{rest[j], rest[j + 3]}] = v1.size() - 1;
// fprintf(out, "mp %d %d = %d\n", rest[j], rest[j + 3], mp[{rest[j], rest[j + 3]}]);
v1.push_back(rest[j + 1]), v2.push_back((rest[j + 3]));
mp[{rest[j + 1], rest[j + 3]}] = v1.size() - 1;
// fprintf(out, "mp %d %d = %d\n", rest[j + 1], rest[j + 3], mp[{rest[j + 1], rest[j + 3]}]);
}
}
}
// fprintf(out, "%d %d\n",(li) rest.size(), cnt + (li)v1.size());
}
// fprintf(out, "%d %d\n", (li)v1.size(), (li)v2.size()); fflush(out);
if(i != 12 && i != 10 && i != 8 && i != 6) v3 = ask(v1, v2);
if(i != 12 && i != 10 && i != 8 && i != 6) cnt += v3.size();
li now = 0;
if(i != 12 && i != 10 && i != 8 && i != 6) for(li j = 0; j < (li)rest.size(); j += 2){
if(j + 1 < (li)rest.size()){
rest2.push_back((v3[now]));
now++;
} else{
rest2.push_back(rest[j]);
}
}
v1.clear(), v2.clear();
rest = rest2;
// fprintf(out, "%d %d\n", (li)rest.size(), cnt); fflush(out);
rest2.clear();
}
// fprintf(out, "%d\n", (li)rest.size()); fflush(out);
for(li i = 0; i < (li)rest.size(); i++){
for(li j = i + 1; j < (li)rest.size(); j++){
v1.push_back(rest[i]), v2.push_back((rest[j]));
}
}
v3 = ask(v1, v2);
li now = 0;
n = rest.size();
for(li i = 0; i < n; i++){
for(li j = i + 1; j < n; j++){
a[i][j] = 0;
if(v3[now] == rest[i]) a[i][j] = 1;
now++;
a[j][i] = !a[i][j];
}
a[i][i] = 1;
}
for(li i = 0; i < n; i++){
li cnt = 0;
for(li j = 0; j < n; j++){
cnt += a[i][j];
}
if(cnt == n) return rest[i];
}
v1.clear(), v2.clear();
// return 1;
}
//int main(){
// // freopen("wonderful.ans", "r", stdin);
// // freopen("www.ww", "w", stdout);
//
// return 0;
//}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Pretest #1:
score: 15
Accepted
time: 640ms
memory: 41428kb
input:
1000 1 499500 957319859
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Pretest #2:
score: 0
Wrong Answer
time: 200ms
memory: 103584kb
input:
1000000 20 2000000 29091473
output:
Wrong answer 4459638610240858557 0.000000 6906350380861515327
result:
points 0.0 Wrong answer
Final Tests
Test #1:
score: 15
Accepted
time: 632ms
memory: 39248kb
input:
1000 1 499500 957319857
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Test #2:
score: 0
Wrong Answer
time: 208ms
memory: 103748kb
input:
1000000 20 2000000 29091471
output:
Wrong answer 4459638610240858557 0.000000 6906350380861515327
result:
points 0.0 Wrong answer