Submission #493929

# Submission time Handle Problem Language Result Execution time Memory
493929 2021-12-13T11:57:02 Z hohohaha Popcount (COCI19_popcount) C++14
110 / 110
4 ms 512 KB
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include "bits/stdc++.h"
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

#define li long long
#define ld long double
#define ii pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>


#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define em emplace
#define ob pop_back
#define om pop
#define of pop_front

#define fr front
#define bc back

#define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); ++i)
#define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); --i)

#define all(x) begin(x), end(x)
#define sz(x) ((int)(x).size())
#define bitc __builtin_popcountll

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define endl '\n'
//#define sp ' '

#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

void solve();

signed main() {
// freopen("input.inp","r",stdin);
// freopen("output.out","w",stdout);
   fastio();
   int tc = 1;
   fori(test, 1, tc) {
      solve();
   }
   return 0;
}

//#define int long long
const ld pi = 4 * atan(1.0), eps = 1e-9;

typedef struct vector<int> bigint; 

bigint operator + (bigint a, bigint b) { 
	int len = max(a.size(), b.size()) + 1; 
	
	a.resize(len, 0); 
	b.resize(len, 0); 
	
	bigint res(len, 0);
	
	int carry = 0; 
	fori(i, 0, len - 1) { 
		res[i] = a[i] + b[i] + carry; 
		
		if(res[i] >= 10) { 
			res[i] -= 10; 
			carry = 1; 
		}
		
		else  { 
			carry = 0; 
		}
	}
	
	if(res.back() == 0 and res.size() >= 2) res.pop_back(); 
	
	return res; 
}

string tos(bigint a) { 
	int len = a.size(); 
	
	string res; 
	
	fori(i, 0, len - 1) { 
		res.push_back(char(a[i] + '0')); 
		assert(a[i] < 10); 
	}
	
	reverse(all(res)); 
	
	return res; 
}

bigint pw[505]; 

void solve() {
	int n, k; 
	cin >> n >> k; 
	pw[0] = vi(1, 1); 
	fori(i,1, n) { 
		pw[i] = pw[i - 1] + pw[i - 1];  
	}
	
	int q = ceil(log2(n));
	
	assert(q <= k); 
	
	cout << q << endl;
	
	fori(bit, 0, q - 1) {
		cout << "A=(";  
		bigint sum1 = vi(1, 0), sum0 = vi(1, 0); 
		fori(i, 0, n - 1) { 
			if(i / (1 << bit) & 1) { 
				sum1 = sum1 + pw[i]; 
				
//				cout<<bit << ' ' << i << ' ' << tos(pw[i]) << endl; 
			}
			else { 
				sum0 = sum0 + pw[i]; 
			}
		}
		cout << "(A&" << tos(sum0) << ")+((A&" << tos(sum1) << ")>>" << (1 << bit) << ")"; 
		cout << ")" << endl; 
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Accepted.
2 Correct 1 ms 204 KB Accepted.
3 Correct 1 ms 204 KB Accepted.
4 Correct 1 ms 204 KB Accepted.
5 Correct 0 ms 204 KB Accepted.
6 Correct 0 ms 204 KB Accepted.
7 Correct 0 ms 204 KB Accepted.
8 Correct 0 ms 204 KB Accepted.
9 Correct 0 ms 204 KB Accepted.
10 Correct 1 ms 332 KB Accepted.
11 Correct 1 ms 332 KB Accepted.
12 Correct 1 ms 204 KB Accepted.
13 Correct 0 ms 204 KB Accepted.
14 Correct 0 ms 204 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Accepted.
2 Correct 1 ms 204 KB Accepted.
3 Correct 1 ms 332 KB Accepted.
4 Correct 1 ms 208 KB Accepted.
5 Correct 0 ms 332 KB Accepted.
6 Correct 1 ms 208 KB Accepted.
7 Correct 1 ms 208 KB Accepted.
8 Correct 1 ms 332 KB Accepted.
9 Correct 1 ms 208 KB Accepted.
10 Correct 0 ms 208 KB Accepted.
11 Correct 1 ms 336 KB Accepted.
12 Correct 0 ms 336 KB Accepted.
13 Correct 1 ms 336 KB Accepted.
14 Correct 1 ms 336 KB Accepted.
15 Correct 1 ms 336 KB Accepted.
16 Correct 1 ms 336 KB Accepted.
17 Correct 1 ms 336 KB Accepted.
18 Correct 1 ms 208 KB Accepted.
19 Correct 1 ms 332 KB Accepted.
20 Correct 1 ms 352 KB Accepted.
21 Correct 1 ms 208 KB Accepted.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Accepted.
2 Correct 2 ms 332 KB Accepted.
3 Correct 3 ms 460 KB Accepted.
4 Correct 4 ms 512 KB Accepted.
5 Correct 2 ms 332 KB Accepted.
6 Correct 1 ms 332 KB Accepted.
7 Correct 1 ms 332 KB Accepted.
8 Correct 1 ms 332 KB Accepted.
9 Correct 1 ms 332 KB Accepted.
10 Correct 2 ms 332 KB Accepted.
11 Correct 2 ms 332 KB Accepted.
12 Correct 3 ms 460 KB Accepted.