QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#288149 | #7749. A Simple MST Problem | UNos_maricones# | WA | 260ms | 68360kb | C++17 | 1.4kb | 2023-12-22 05:07:34 | 2023-12-22 05:07:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1000'100;
const int INF = (int) 1e9;
bool cmp[N];
int rn[N];
vector< int > primes[N];
int solve()
{
int l, r;
cin >> l >> r;
const int n = ( r - l + 1 );
vector< int > v;
for( int i = l; i <= r; ++ i )
v.push_back( rn[i] );
sort( v.begin(), v.end() );
vector< int > mn_cost_mul( r + 1, INF );
int ans = 0;
for( int i = 0; i < n; ++ i )
{
const int x = v[i];
const int wx = (int) primes[x].size();
int mn_cost = INF;
for( int mask = 0; mask < ( 1 << wx ); ++ mask )
{
int div = 1, wdiv = 0;
for( int j = 0; j < wx; ++ j )
if( mask >> j & 1 )
div *= primes[x][j], ++wdiv;
mn_cost = min( mn_cost, mn_cost_mul[div] - wdiv );
mn_cost_mul[div] = min( mn_cost_mul[div], wx );
}
mn_cost += wx;
if( i != 0 ) ans += mn_cost;
}
return ans;
}
int main()
{
cin.tie( NULL );
ios_base::sync_with_stdio( 0 );
iota( rn, rn + N, 0 );
for( int i = 2; i < N; ++ i )
{
if( !cmp[i] )
{
long long i2 = 1LL * i * i;
for( int j = i; j < N; j += i )
{
cmp[j] = true;
if( j % i2 == 0 )
rn[j] = j/i;
primes[j].push_back( i );
}
}
if( rn[i] != i )
rn[i] = rn[rn[i]];
}
int t;
cin >> t;
while( t-- )
cout << solve() << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 173ms
memory: 63716kb
input:
5 1 1 4 5 1 4 1 9 19 810
output:
0 2 3 9 1812
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 208ms
memory: 64744kb
input:
2 27 30 183704 252609
output:
8 223092
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 195ms
memory: 64644kb
input:
1 183704 252609
output:
223092
result:
ok single line: '223092'
Test #4:
score: 0
Accepted
time: 219ms
memory: 68360kb
input:
2 639898 942309 30927 34660
output:
983228 11512
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 228ms
memory: 66280kb
input:
3 21731 33468 46192 370315 1712 3753
output:
34608 948775 5299
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 187ms
memory: 64452kb
input:
4 15237 67700 10918 86104 98287 116980 17432 23592
output:
148811 210927 60893 18687
result:
ok 4 lines
Test #7:
score: 0
Accepted
time: 260ms
memory: 67100kb
input:
5 5594 70302 19202 69588 5634 7877 59821 469300 97439 261121
output:
179735 145706 6565 1203684 488669
result:
ok 5 lines
Test #8:
score: 0
Accepted
time: 233ms
memory: 65360kb
input:
6 43477 229639 188276 269887 72424 150178 9009 36918 137421 180271 14666 124530
output:
541705 255651 232054 77284 135277 313203
result:
ok 6 lines
Test #9:
score: 0
Accepted
time: 204ms
memory: 65568kb
input:
7 461436 501798 98856 148334 20953 119408 910 5027 762 14117 10959 46088 96149 130311
output:
139017 151124 281536 10504 34818 98004 108375
result:
ok 7 lines
Test #10:
score: 0
Accepted
time: 239ms
memory: 66568kb
input:
8 6448 11162 33691 94044 137536 140277 106719 267437 13494 38185 3185 4173 4835 299526 25162 43201
output:
13177 175485 9711 480992 69059 2808 840950 53422
result:
ok 8 lines
Test #11:
score: 0
Accepted
time: 226ms
memory: 65040kb
input:
9 4136 54985 38425 155322 107602 157683 115533 137627 13677 44903 43432 69310 70004 129314 43033 55373 76424 147123
output:
139668 339337 153266 68520 87592 76612 183238 39109 211339
result:
ok 9 lines
Test #12:
score: -100
Wrong Answer
time: 237ms
memory: 65564kb
input:
10 21662 27103 55634 196143 20466 44902 87028 202799 127745 151602 1598 1679 95299 126981 13367 134183 52307 66285 10136 38071
output:
17117 410126 71979 344673 74754 264 100586 342577 41870 77522
result:
wrong answer 6th lines differ - expected: '263', found: '264'