QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#143310 | #7026. Let the Flames Begin | Sorting# | WA | 2ms | 3532kb | C++20 | 1.9kb | 2023-08-21 01:43:59 | 2023-08-21 01:44:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
int test_id ;
void solve ( ) {
ll n , m , k ;
cin >> n >> m >> k ;
++ test_id ;
cout << "Case #" << test_id << ": " ;
if ( k == 1 ) {
cout << m << "\n" ;
return ;
}
if ( k <= m ) {
ll taken = 0 , rem = n ;
ll x = k ;
vector < ll > v ;
ll ans = -1 ;
int ctr = 0 ;
while ( 1 ) {
ll tot = 1 + ( rem - x ) / k ;
++ ctr ;
if ( ctr >= 10 ) { break ; }
if ( taken + tot >= m ) {
ans = x + ( m - taken - 1 ) * k ;
if ( ans > rem ) { ans -= rem ; }
break ;
}
else {
v.push_back ( x ) ;
x += tot * k ;
x %= rem ;
if ( x == 0 ) { x += k ; }
taken += tot , rem -= tot ;
}
}
reverse ( v.begin ( ) , v.end ( ) ) ;
for ( auto st : v ) {
if ( st <= ans ) {
ll coef = 1 + ( ans - st ) / ( k - 1 ) ;
ans += coef ;
}
}
cout << ans << "\n" ;
}
else {
ll ans = 0 ;
for ( ll i = n - m + 1 ; i <= n ; ++ i ) {
ll pos = k % i ;
if ( pos == 0 ) { pos = i ; }
ans = ans + pos ;
if ( ans > i ) { ans -= i ; }
}
cout << ans << "\n" ;
}
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
input:
20 10 1 2 10 2 2 10 3 2 10 4 2 10 5 2 10 6 2 10 7 2 10 8 2 10 9 2 10 10 2 10 1 3 10 2 3 10 3 3 10 4 3 10 5 3 10 6 3 10 7 3 10 8 3 10 9 3 10 10 3
output:
Case #1: 2 Case #2: 4 Case #3: 6 Case #4: 8 Case #5: 10 Case #6: 3 Case #7: 7 Case #8: 1 Case #9: 9 Case #10: 5 Case #11: 3 Case #12: 6 Case #13: 9 Case #14: 2 Case #15: 7 Case #16: 1 Case #17: 8 Case #18: 5 Case #19: 10 Case #20: 4
result:
ok 20 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3532kb
input:
1000 999999999999992561 159 395327336264586619 442108849746740138 442108849746736034 460 999999999999992483 170 493046129512466597 999999999999994068 441 350960072694194744 999999999999995777 999999999999990118 67 999999999999991275 999999999999983373 331 999999999999990404 999999999999985608 429 99...
output:
Case #1: 857046466069738524 Case #2: -1 Case #3: 817842017119952395 Case #4: 773392058140829462 Case #5: -1 Case #6: -1 Case #7: -1 Case #8: 233100 Case #9: 641511906156530773 Case #10: -1 Case #11: 230107545980257170 Case #12: 107498742817125489 Case #13: -1 Case #14: -1 Case #15: -1 Case #16: 4681...
result:
wrong answer 2nd lines differ - expected: 'Case #2: 294578226925711387', found: 'Case #2: -1'