답안 #860300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860300 2023-10-12T14:04:27 Z nnhzzz 조교 (CEOI16_popeala) C++14
0 / 100
2000 ms 10844 KB
// cre: Nguyen Ngoc Hung - Train VOI 2024 :>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <array>
#include <cassert>
#include <random>

using namespace std;

#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define                fi  first
#define                se  second
#define                ll  long long
#define                vi  vector<int>
#define               vvi  vector<vi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define REPDIS(i,be,en,j)  for(int i = (be); i<=(en); i+=j)
#define     REPD(i,be,en)  for(int i = (be); i>=(en); i--)
#define      REP(i,be,en)  for(int i = (be); i<=(en); i++)
//-------------------------------------------------------------//
const int oo = 1e9,LOG = 20,MAXN = 2e4+3,N = 53;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

int f[MAXN],pre[MAXN][N],dp[MAXN][N], l[MAXN][N];
int n,t,s,ok[MAXN];

int cost(int l, int r){
    int k = r-l+1,res = 0;
    REP(i,1,n){
        res += (pre[r][i]-pre[l-1][i])==k;
    }
    return res*(f[r]-f[l-1]);
}

void solve(){
    cin >> n >> t >> s;
    REP(i,1,t){
        cin >> f[i];
        f[i] += f[i-1];
    }
    REP(i,1,n){
        REP(j,1,t){
            char ch; cin >> ch;
            pre[j][i] = pre[j-1][i]+(ch=='1');

            if (ch == '1') {
                if (ok[j - 1])
                    l[j][i] = l[j - 1][i];
                else
                    l[j][i] = j;

                ok[j] = 1;
            } else l[j][i] = 0;
        }
    }
    memset(dp,0x3f,sizeof dp);

    dp[0][0] = 0;
    REP(k,1,s){
        REP(i,k,t){
            static vector<int> ok;

            ok.clear();
            REP(j,1,n) {
                if (l[i][j]) {
                    int u = i;
                    for (int _ = 1; _ <= k; ++_) {
                        if (u != 0) {
                            ok.push_back(u);
                            if (u - 1) ok.push_back(u - 1);
                            u = l[u - 1][j];
                        }
                    }
                } 

                {
                    for (int l = 1; l <= s; ++l) if (i>=l) ok.push_back(i-l+1);
                }
            }

            // cout << i << ": "; for (auto &x: ok) cout << x << " "; cout << "\n";

            for (auto &x: ok)
                mini(dp[i][k], dp[x - 1][k - 1] + cost(x, i));
        }
        cout << dp[t][k] << '\n';
    }
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define name "test"
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    #define name1 "nnhzzz"
    if(fopen(name1".inp","r")){
        freopen(name1".inp","r",stdin);
        freopen(name1".out","w",stdout);
    }

    int test = 1;

    while(test--){
      solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:149:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:150:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  150 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:154:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |         freopen(name1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:155:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  155 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 11 ms 6604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 10844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2084 ms 10840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Incorrect 11 ms 6604 KB Output isn't correct
3 Halted 0 ms 0 KB -