답안 #609001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
609001 2022-07-27T11:42:56 Z farhan132 조교 (CEOI16_popeala) C++17
26 / 100
2000 ms 10180 KB
/***Farhan132***/
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef int ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm; 
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
 
//const ll mod =  (ll) 998244353;
const ll mod =  (ll) 1e9 + 7;
const ll maxn = (ll)1e8 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const int inf = 1e9 + 9;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)1e18;
 
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};
 
bool USACO = 0;
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll N = 20005;

ll a[N];

struct seg_tree{

  struct typo{
    ll mn = 0;
    void setup(ll _sum){
      mn = _sum;
    }
  };

  vector < typo > b;
  ll n;

  void init(ll l, ll r, ll node){
    b[node].setup(a[l]);
    return;
  }

  typo merge(typo a, typo b){
    typo c;
    c.mn = min(a.mn, b.mn);
    return c;
  }

  void build(ll l, ll r, ll node){
    if(l == r){
      init(l,r,node);
      return;
    }
    ll mid = (l + r)/2;
    ll n1 = 2*node;
    ll n2 = n1 + 1;
    build(l, mid , n1);
    build(mid+1, r, n2);
    b[node] = merge(b[n1] , b[n2]);
    return;
  }

  void build(ll _n){
    n = _n;
    b.resize(4*n);
    build(1,n,1); // optional
  }

  typo get(ll l, ll r, ll node, ll x, ll y){
    if(y < l || x > r) return {inf};
    if(x <= l && y >= r){
      return b[node];
    }
    ll mid = (l + r)/2;
    ll n1 = 2*node;
    ll n2 = n1 + 1;
    return merge(get(l , mid , n1 , x , y) , get(mid + 1, r , n2 , x , y));
  }

  ll get(ll l, ll r){
    return get(1,n,1,l,r).mn;
  }

  /* Final Check!!!
     1. Typo, Okay?
     2. Init Okay? (Build!!)
     3. Merge, Okay?
     4. Lazy Needed ? YES | NO (if NO, REMOVE anything related to lazy prop)
     5. Dummy?
     6. Check Update, Get, etc function's Merge, Lazy Prop , Init :D
     7, Even after a WA, check for possible Out Of Bound/MLE/RE cases
  */

};



vector < ll > v[55];
ll dp[N][55];
ll sum[N];

void solve(){

    ll T, n, s;
    cin >> n >> T >> s;

    mem(sum, 0);

    for(ll i = 1; i <= T; i++){
        cin >> sum[i];
        sum[i] += sum[i - 1];
    }
    sum[T+1] += sum[T];

    for(ll i = 1; i <= n; i++){
        for(ll j = 1; j <= T; j++){
            char x; cin >> x;
            if(x == '0') v[i].pb(j);
        }
    }

    mem(dp, 0);
    for(ll i = 1; i <= s; i++) dp[T+1][i] = inf;
    for(ll i = 1; i <= T; i++) dp[i][0] = inf;
    for(ll j = 1; j <= s; j++){
        seg_tree DS[n+1];
        for(ll x = 0; x <= n; x++){
            for(ll i = 1; i <= T; i++){
             if(dp[i+1][j-1] == inf){
                a[i] = inf; continue;
             }
             a[i] = sum[i] * x + dp[i+1][j-1];
            }
            DS[x].build(T);
        }
        for(ll i = T; i >= 1; i--){
            vector < ll > nxt;
            for(ll x = 1; x <= n; x++){
                auto it = lower_bound(v[x].begin(), v[x].end(), i);
                if(it != v[x].end()) nxt.pb(*it);
            }
            ll tot = n + 1; nxt.pb(i);
            sort(nxt.begin(), nxt.end());
            ll cur = i, _i = 0;
            dp[i][j] = inf;
            while(_i < nxt.size()){
                while(_i < nxt.size() && nxt[_i] == cur) _i++, tot--;
                
                ll l = cur;
                if(_i < nxt.size()) cur = nxt[_i];
                else cur = T + 1;
                ll r = cur - 1; ll kk = DS[tot].get(l, r);
                if(kk == inf) continue;
                dp[i][j] = min(dp[i][j], -sum[i - 1]*tot + kk);
            }
            //dp[i][j] = min(dp[T+1][j - 1] + tot*(sum[T] - sum[i - 1]), dp[i][j]);
        }
    }
    for(ll i = 1; i <= s; i++){
        cout << dp[1][i] << '\n';
    }

  return;
}
int main() {
    
    
    #ifdef LOCAL
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
        auto start_time = clock();
    #else 
       ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif

    ll T = 1, CT = 0;// cin >> T;
 
    while(T--){
        solve();
    }
    #ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
    #endif
 
    return 0;
} 

Compilation message

popeala.cpp: In function 'void solve()':
popeala.cpp:189:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  189 |             while(_i < nxt.size()){
      |                   ~~~^~~~~~~~~~~~
popeala.cpp:190:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  190 |                 while(_i < nxt.size() && nxt[_i] == cur) _i++, tot--;
      |                       ~~~^~~~~~~~~~~~
popeala.cpp:193:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  193 |                 if(_i < nxt.size()) cur = nxt[_i];
      |                    ~~~^~~~~~~~~~~~
popeala.cpp: In function 'int main()':
popeala.cpp:219:15: warning: unused variable 'CT' [-Wunused-variable]
  219 |     ll T = 1, CT = 0;// cin >> T;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4692 KB Output is correct
2 Correct 4 ms 4732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 5108 KB Output is correct
2 Correct 113 ms 5088 KB Output is correct
3 Correct 117 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 674 ms 6484 KB Output is correct
2 Correct 1026 ms 7284 KB Output is correct
3 Correct 1265 ms 7988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4692 KB Output is correct
2 Correct 4 ms 4732 KB Output is correct
3 Correct 132 ms 5108 KB Output is correct
4 Correct 113 ms 5088 KB Output is correct
5 Correct 117 ms 5076 KB Output is correct
6 Correct 674 ms 6484 KB Output is correct
7 Correct 1026 ms 7284 KB Output is correct
8 Correct 1265 ms 7988 KB Output is correct
9 Execution timed out 2032 ms 10180 KB Time limit exceeded
10 Halted 0 ms 0 KB -