Submission #925560

# Submission time Handle Problem Language Result Execution time Memory
925560 2024-02-12T04:54:00 Z ttamx Ancient Machine 2 (JOI23_ancient2) C++17
97 / 100
36 ms 2020 KB
#include "ancient2.h"
#include<bits/stdc++.h>

using namespace std;

const int N=1000;
const int Q=1000;

using BS = bitset<N>;
using VBS = vector<BS>;

struct Basis{
	VBS basis;
	int n,cnt;
	Basis(){}
	Basis(int _n){
		init(_n);
	}
	void init(int _n){
		n=_n;
		cnt=0;
		basis.assign(_n,BS{});
	}
	bool insert(BS v){
		for(int i=0;i<n;i++){
			if(v[i]){
				if(basis[i][i]){
					v^=basis[i];
				}else{
					basis[i]=v;
					cnt++;
					return true;
				}
			}
		}
		return false;
	}
};

void gaussian_elimation(int n,VBS &a,vector<int> &b){
	for(int i=0;i<n;i++){
		int id=i;
		while(!a[id][i])id++;
		swap(a[i],a[id]);
		swap(b[i],b[id]);
		for(int j=0;j<n;j++)if(i!=j&&a[j][i]){
			a[j]^=a[i];
			b[j]^=b[i];
		}
	}
}

bool ask(int n,int m,int r){
	vector<int> a(m*2),b(m*2);
	for(int i=0;i<m;i++){
		int p=(i+1)%m;
		a[i]=b[i]=p;
		a[i+m]=b[i+m]=p+m;
	}
	int p=(r+1)%m;
	b[r]=m+p;
	b[r+m]=p;
	return Query(2*m,a,b)>=m;
}

string Solve(int n) {
	Basis basis(n);
	VBS mat;
	vector<int> ans;
	int max_q=0;
	for(int m=2;m<Q/2;m++){
		for(int r=0;r<m;r++){
			BS res;
			for(int i=r;i<n;i+=m)res[i]=true;
			if(basis.insert(res)){
				mat.emplace_back(res);
				ans.emplace_back(ask(n,m,r));
				if(basis.cnt==n)break;
 			}
		}
		if(basis.cnt==n)break;
	}
	gaussian_elimation(n,mat,ans);
	string res="";
	for(auto x:ans)res.push_back('0'+x);
	return res;
}

Compilation message

ancient2.cpp: In function 'std::string Solve(int)':
ancient2.cpp:70:6: warning: unused variable 'max_q' [-Wunused-variable]
   70 |  int max_q=0;
      |      ^~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 31 ms 1720 KB Output is partially correct
2 Partially correct 28 ms 1496 KB Output is partially correct
3 Partially correct 30 ms 1784 KB Output is partially correct
4 Partially correct 29 ms 1432 KB Output is partially correct
5 Partially correct 29 ms 1560 KB Output is partially correct
6 Partially correct 29 ms 1972 KB Output is partially correct
7 Partially correct 30 ms 1772 KB Output is partially correct
8 Partially correct 30 ms 1924 KB Output is partially correct
9 Partially correct 28 ms 1532 KB Output is partially correct
10 Partially correct 30 ms 1732 KB Output is partially correct
11 Partially correct 29 ms 1996 KB Output is partially correct
12 Partially correct 30 ms 1516 KB Output is partially correct
13 Partially correct 30 ms 1480 KB Output is partially correct
14 Partially correct 29 ms 1460 KB Output is partially correct
15 Partially correct 30 ms 1564 KB Output is partially correct
16 Partially correct 29 ms 1680 KB Output is partially correct
17 Partially correct 30 ms 1488 KB Output is partially correct
18 Partially correct 31 ms 2020 KB Output is partially correct
19 Partially correct 28 ms 1280 KB Output is partially correct
20 Partially correct 29 ms 1460 KB Output is partially correct
21 Partially correct 29 ms 1448 KB Output is partially correct
22 Partially correct 29 ms 1268 KB Output is partially correct
23 Partially correct 29 ms 1020 KB Output is partially correct
24 Partially correct 29 ms 1472 KB Output is partially correct
25 Partially correct 31 ms 1992 KB Output is partially correct
26 Partially correct 29 ms 1788 KB Output is partially correct
27 Partially correct 29 ms 1296 KB Output is partially correct
28 Partially correct 29 ms 1244 KB Output is partially correct
29 Partially correct 29 ms 1436 KB Output is partially correct
30 Partially correct 28 ms 1704 KB Output is partially correct
31 Partially correct 29 ms 1492 KB Output is partially correct
32 Partially correct 29 ms 1388 KB Output is partially correct
33 Partially correct 28 ms 1256 KB Output is partially correct
34 Partially correct 29 ms 1768 KB Output is partially correct
35 Partially correct 28 ms 796 KB Output is partially correct
36 Partially correct 31 ms 1716 KB Output is partially correct
37 Partially correct 29 ms 968 KB Output is partially correct
38 Partially correct 29 ms 980 KB Output is partially correct
39 Partially correct 30 ms 1524 KB Output is partially correct
40 Partially correct 30 ms 1712 KB Output is partially correct
41 Partially correct 29 ms 1256 KB Output is partially correct
42 Partially correct 30 ms 776 KB Output is partially correct
43 Partially correct 29 ms 1272 KB Output is partially correct
44 Partially correct 29 ms 1512 KB Output is partially correct
45 Partially correct 31 ms 1536 KB Output is partially correct
46 Partially correct 29 ms 1536 KB Output is partially correct
47 Partially correct 29 ms 2012 KB Output is partially correct
48 Partially correct 30 ms 1532 KB Output is partially correct
49 Partially correct 30 ms 1484 KB Output is partially correct
50 Partially correct 29 ms 1780 KB Output is partially correct
51 Partially correct 31 ms 1972 KB Output is partially correct
52 Partially correct 28 ms 1220 KB Output is partially correct
53 Partially correct 30 ms 1516 KB Output is partially correct
54 Partially correct 29 ms 1500 KB Output is partially correct
55 Partially correct 29 ms 1036 KB Output is partially correct
56 Partially correct 36 ms 1356 KB Output is partially correct
57 Partially correct 31 ms 1640 KB Output is partially correct
58 Partially correct 31 ms 1492 KB Output is partially correct
59 Partially correct 30 ms 1292 KB Output is partially correct
60 Partially correct 29 ms 1264 KB Output is partially correct
61 Partially correct 32 ms 1416 KB Output is partially correct
62 Partially correct 30 ms 1272 KB Output is partially correct
63 Partially correct 29 ms 1768 KB Output is partially correct