Submission #723519

# Submission time Handle Problem Language Result Execution time Memory
723519 2023-04-14T02:38:53 Z vjudge1 Timovi (COCI18_timovi) C++17
30 / 80
66 ms 13184 KB
#include <bits/stdc++.h>
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define sts stable_sort
using namespace std;

const int MAXN = 1e6 + 4;
const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    ll n, k, m; cin >> n >> k >> m;
    if(n == 1){
        cout << m << "\n";
        return 0;
    }
    map<ll, ll> ma;

    if(m / k < n){
        bool a = 0;
        for(int i = 1; m > 0; ){
            if(m >= k){
                ma[i] += k;
                m -= k;
            }else{
                ma[i] += m;
                m = 0;
            }
            if(m == 0)break;
            if(i == 1 && a){
                a = 0;
            }else if(i == n && !a){
                a = 1;
            }
            if(a)i--;
            else i++;
        }
        for(int i = 1; i <= n; i++){
            cout << ma[i] << " ";
        }cout << "\n";
        return 0;
    }
    if(k == 1){
        ll cnt = 0, n_ = n, m_;
        while(n > 0){
            m_ = m - n;
            n -= m;
            cnt ++;
        }
        if(cnt % 2 == 0){
            bool a = 0;
            for(int i = 2; m_ > 0; ){
                if(m_ >= k){
                    ma[i] += k;
                    m_ -= k;
                }else{
                    ma[i] += m_;
                    m_ = 0;
                }
                if(m_ == 0){
                    break;
                }
                if(i == n_ && !a){
                    a = 1;
                }else if(i == 1 && a){
                    a = 0;
                }
                if(a)i--;
                else i++;
            }
        }else{
            bool a = 0;
            for(int i = n_ - 1; m_ > 0;){
                if(m_ >= k){
                    ma[i] += k;
                    m_ -= k;
                }else{
                    ma[i] += m_;
                    m_ = 0;
                }
                if(m_ == 0){
                    break;
                }
                if(i == 1 && !a){
                    a = 1;
                }else if(i == n_ && a){
                    a = 0;
                }
                if(a)i++;
                else i--;
            }
        }
        for(int i = 1; i <= n_; i++){
            cout << ma[i] + cnt << " ";
        }cout << "\n";
        return 0;
    }
    if(m % k == 0){
        if(m / k == n){
            for(ll i = 0; i < n; i++){
                cout << k << " ";
            }
            return 0;
        }
    }
    ll cnt = 0;
    ll k_ = k, ak = k;
    while(m / k >= n){
        k *= m / k;
        cnt++;
    }
    ll m_ = m - k;
    if(cnt % 2 == 0){
        for(ll i = 1; i <= n; i++){
            if(m_ >= k_){
                ma[i] += k_;
                m_ -= k_;
            }else{
                ma[i] += m_;
                m_ = 0;
            }
            if(m_ == 0)break;
        }
    }else{
        for(ll i = n - 1; i >= 1; i--){
            if(m_ >= k_){
                ma[i] += k_;
                m_ -= k_;
            }else{
                ma[i] += m_;
                m_ = 0;
            }
            if(m_ == 0)break;
        }
    }
    for(ll i = 1; i <= n; i++){
        cout << ma[i] + (cnt * ak) << " ";
    }cout << "\n";

    return 0;
}

Compilation message

timovi.cpp: In function 'int main()':
timovi.cpp:65:24: warning: 'm_' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |                     m_ -= k;
      |                     ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Correct 60 ms 13184 KB Output is correct
4 Correct 55 ms 13184 KB Output is correct
5 Incorrect 1 ms 316 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 66 ms 13156 KB Output isn't correct
8 Incorrect 59 ms 13140 KB Output isn't correct