Submission #609183

# Submission time Handle Problem Language Result Execution time Memory
609183 2022-07-27T12:41:11 Z farhan132 Popeala (CEOI16_popeala) C++17
17 / 100
1002 ms 17748 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 long long 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;
 
vector < ll > v[55];
ll dp[N][55];
ll last[N][55];
ll sum[N];
 
void solve(){
 
    ll T, n, s;
    cin >> n >> T >> s;
 
    mem(sum, 0);
    mem(last, -1);
 
    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) , last[j][i] = j;
            else last[j][i] = last[j - 1][i];
        }
    }
 
    mem(dp, 0);
    for(ll i = 1; i <= s; i++) dp[T+1][i] = 1e18;
    for(ll i = T; i >= 1; i--){
        dp[i][0] = 1e18;
        for(ll j = 1; j <= s; j++){
            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] = 1e18;
            while(_i < nxt.size()){
                while(_i < nxt.size() && nxt[_i] == cur) _i++, tot--;
                dp[i][j] = min(dp[cur + 1][j - 1] + tot*(sum[cur] - sum[i - 1]), dp[i][j]);
                ll l = cur;
                if(_i < nxt.size()) cur = nxt[_i];
                else cur = T + 1;
                
                dp[i][j] = min(dp[cur][j - 1] + tot*(sum[cur - 1] - sum[i - 1]), dp[i][j]);
                for(ll x = 1; x <= n; x++){
                    ll it = last[cur-1][x];
                    if(it == -1) continue;
                      for(ll c = it + 1; c >= max(l + 1, it - j); c--)
                          dp[i][j] = min(dp[c][j - 1] + tot*(sum[c-1] - sum[i - 1]), dp[i][j]);
                        
                    
                }
            }
            //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:108:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |             while(_i < nxt.size()){
      |                   ~~~^~~~~~~~~~~~
popeala.cpp:109:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                 while(_i < nxt.size() && nxt[_i] == cur) _i++, tot--;
      |                       ~~~^~~~~~~~~~~~
popeala.cpp:112:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |                 if(_i < nxt.size()) cur = nxt[_i];
      |                    ~~~^~~~~~~~~~~~
popeala.cpp: In function 'int main()':
popeala.cpp:145:15: warning: unused variable 'CT' [-Wunused-variable]
  145 |     ll T = 1, CT = 0;// cin >> T;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 17620 KB Output is correct
2 Correct 8 ms 17620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 17708 KB Output is correct
2 Correct 204 ms 17704 KB Output is correct
3 Correct 237 ms 17700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1002 ms 17748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 17620 KB Output is correct
2 Correct 8 ms 17620 KB Output is correct
3 Correct 218 ms 17708 KB Output is correct
4 Correct 204 ms 17704 KB Output is correct
5 Correct 237 ms 17700 KB Output is correct
6 Incorrect 1002 ms 17748 KB Output isn't correct
7 Halted 0 ms 0 KB -