QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387199 | #6512. Completely Multiplicative Function | evirir | WA | 40ms | 12172kb | C++20 | 3.1kb | 2024-04-12 09:11:51 | 2024-04-12 09:11:51 |
Judging History
answer
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define cbug if(DEBUG) cout
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
ostream& operator<<(ostream &out, ii x){ out<<"("<<x.F<<","<<x.S<<")"; return out; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
struct Hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 1000001;
const int LG = 21;
vector<ll> primes, lowprime;
vector<bool> isprime;
void Sieve(ll n) // linear Sieve
{
isprime.assign(n+1, 1);
lowprime.assign(n+1, 0);
isprime[1] = false;
for(ll i = 2; i <= n; i++)
{
if(lowprime[i] == 0)
{
primes.pb(i);
lowprime[i] = i;
}
for(int j=0; j<sz(primes) && primes[j]<=lowprime[i] && i*primes[j]<=n; j++)
{
isprime[i*primes[j]] = false;
lowprime[i*primes[j]] = primes[j];
}
}
}
void solve()
{
int n,K; cin>>n>>K;
if ((n & 1) != (K & 1))
{
cout << -1 << '\n';
return;
}
int sum = n;
int ans[n + 1]{};
fore(i,1,n) ans[i] = 1;
for (const auto p : primes)
{
if (p > n) break;
int con = 0;
for (int i = p; i <= n; i += p)
{
bool par = 0;
int x = i;
while (x % p == 0)
{
par ^= 1;
x /= p;
}
if (!par) continue;
if (ans[i] == 1) con -= 2;
else con += 2;
}
if (abs(sum + con - K) < abs(sum - K))
{
sum += con;
for (int i = p; i <= n; i += p)
{
bool par = 0;
int x = i;
while (x % p == 0)
{
par ^= 1;
x /= p;
}
if (!par) continue;
ans[i] = (ans[i] == 1 ? -1 : 1);
}
}
// cout << "p=" << p << ":";
// fore(i,1,n) cout<<' '<<ans[i];
// cout<<'\n';
}
fore(i,1,n)
{
if (i > 1) cout<<' ';
cout << ans[i];
}
cout<<'\n';
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
Sieve(MAXN);
int t; cin>>t;
fore(i,1,t) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 12172kb
input:
4 4 2 10 0 10 1 10 10
output:
1 -1 1 1 1 -1 1 1 1 -1 -1 -1 1 -1 -1 1 1 1 1 1 1 1 1 1 1
result:
ok ok (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 12112kb
input:
11475 1 0 1 1 2 0 2 1 2 2 3 0 3 1 3 2 3 3 4 0 4 1 4 2 4 3 4 4 5 0 5 1 5 2 5 3 5 4 5 5 6 0 6 1 6 2 6 3 6 4 6 5 6 6 7 0 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 0 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 0 11 1 11 2 11 3 11...
output:
-1 1 1 -1 -1 1 1 -1 1 -1 1 -1 1 1 1 1 -1 -1 1 -1 1 -1 1 1 -1 1 1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 -1 1 -1 1 1 1 -1 -1 1 1 1 1 -1 1 -1 1 1 1 1 1 1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 1 -1 1 1 -1 -1 1 -1 -1 1 -1 1 1 1 -1 1 -1 -1 1 -1 1 ...
result:
wrong answer sum of f is not k (test case 40)