답안 #472829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472829 2021-09-14T11:34:05 Z HossamHero7 Hokej (COCI17_hokej) C++14
0 / 120
162 ms 6468 KB
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef vector <ll> row;
typedef vector <row> matrix;
#define endl '\n'
#define fast ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define all(v) ((v).begin()), ((v).end())
#define allR(v) ((v).rbegin()), ((v).rend())
#define For(i,n) for(int i=0;i<(int)(n);i++)
#define sz(v) v.size()
#define swapS(a,b) if(a>b) swap(a,b)
const ll mod = 1e9+7;
const ll OO = 1e18;
const ll invalid = -1e18;
int dx[] = {0,0,-1,1,1,1,-1,-1};
int dy[] = {1,-1,0,0,1,-1,-1,1};
ll fixMod(ll x){
    return ((x%mod) + mod) % mod;
}
ll lcm(ll a,ll b){
    return max(a,b)/__gcd(a,b)*min(a,b);
}
ll power(ll a,ll b){
    if(b==0) return 1;
    if(b==1) return a;
    if(b&1){
        ll y=power(a,b/2);
        return (y*y*a);
    }
    else {
        ll y=power(a,b/2);
        return (y*y);
    }
}
ll inv(ll n){
    return power(n,(mod-2));
}
matrix zero(int n,int m){
    return matrix(n,row(m,0));
}
matrix identity(int n){
    matrix ret = zero(n,n);
    for(int i=0;i<n;i++){
        ret[i][i] = 1;
    }
    return ret;
}
matrix multiply(const matrix &a, const matrix &b){
    matrix ret = zero(a.size(),b[0].size());
    for(int i=0;i<a.size();i++){
        for(int k=0;k<a[0].size();k++){
            for(int j=0;j<b[0].size();j++){
                ret[i][j] += a[i][k] * b[k][j];
                ret[i][j] = ret[i][j];
            }
        }
    }
    return ret;
}
matrix matrixPower(matrix &a,ll b){
    if(b == 0) return identity(a.size());
    if(b == 1) return a;
    matrix r = matrixPower(a,b/2);
    if(b&1) return multiply(multiply(r,r),a);
    return multiply(r,r);
}
void solve(){
    int m,n;
    cin>>m>>n;
    vector <pair<int,pair<int,int>>> v(n);
    int idx=1;
    for(auto &i:v) cin>>i.first>>i.second.first,i.second.second = idx++;
    sort(allR(v));
    ll sum = 0;
    ll time = 0;
    vector <pair<int,pair<int,int>>> x;
    for(auto i : v){
        if(time >= m*6) break;
        x.push_back({i.first,{min((ll)i.second.first,m*6-time),i.second.second}});
        time += i.second.first;
    }
    for(auto i : x){
        sum += i.first * i.second.first;
    }
    cout<<sum<<endl;
    vector <int> ans1;
    priority_queue <pair<int,int>> q;
    for(int i=0;i<6;i++){
        ans1.push_back(x[i].second.second);
        q.push({-x[i].second.first,x[i].second.second});
    }
    for(auto i : ans1){
        cout<<i<<" ";
    }
    cout<<endl;
    idx = 6;
    vector <pair<int,pair<int,int>>> subt;
    for(int i=1;i<=m;i++){
        if(abs(q.top().first)<i){
            if(idx == x.size()){
                cout<<to_string(n)<<endl;
                return;
            }
            subt.push_back({i,{q.top().second,x[idx].second.second}});
            pair <int,int> temp;
            temp.first = -(x[idx].second.first + i);
            temp.second = x[idx].second.second;
            q.pop();
            q.push(temp);
            idx ++;
            i--;
        }
    }
    cout<<subt.size()<<endl;
    for(auto i : subt){
        cout<<i.first<<" "<<i.second.first<<" "<<i.second.second<<endl;
    }
}
int main()
{
    fast
    ll t=1;
    // cin>>t;
    while(t--){
        //Some important Notes:
        //  1- Any minus with mod fixed mod
        //  2- Any divide with mod inverse
        //  3- Any mod problem make mod in every where
        //  4- Any dp problem don't forget to return the saved value :)
        solve();
    }
    return 0;
}

Compilation message

hokej.cpp: In function 'matrix multiply(const matrix&, const matrix&)':
hokej.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
hokej.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int k=0;k<a[0].size();k++){
      |                     ~^~~~~~~~~~~~
hokej.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for(int j=0;j<b[0].size();j++){
      |                         ~^~~~~~~~~~~~
hokej.cpp: In function 'void solve()':
hokej.cpp:102:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             if(idx == x.size()){
      |                ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Failed 0 ms 204 KB some player fainted
2 Incorrect 3 ms 332 KB Unexpected end of file - int32 expected
3 Incorrect 8 ms 588 KB Unexpected end of file - int32 expected
4 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
5 Incorrect 4 ms 460 KB Unexpected end of file - int32 expected
6 Failed 1 ms 332 KB some player fainted
7 Incorrect 3 ms 332 KB Unexpected end of file - int32 expected
8 Incorrect 30 ms 1744 KB Unexpected end of file - int32 expected
9 Incorrect 162 ms 6468 KB Unexpected end of file - int32 expected
10 Incorrect 161 ms 6444 KB Unexpected end of file - int32 expected