답안 #608931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
608931 2022-07-27T11:16:49 Z farhan132 조교 (CEOI16_popeala) C++17
8 / 100
2000 ms 9092 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 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] = 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++){
                    auto it = lower_bound(v[x].begin(), v[x].end(), cur);
                    if(it != v[x].begin()){
                        --it;
                        if(*it >= l){
                          dp[i][j] = min(dp[*it + 1][j - 1] + tot*(sum[*it] - sum[i - 1]), dp[i][j]);
                          if(*it > l) dp[i][j] = min(dp[*it][j - 1] + tot*(sum[*it - 1] - sum[i - 1]), dp[i][j]);
                          if(*it - 1 > l) dp[i][j] = min(dp[*it - 1][j - 1] + tot*(sum[*it - 2] - 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:105: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]
  105 |             while(_i < nxt.size()){
      |                   ~~~^~~~~~~~~~~~
popeala.cpp:106: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]
  106 |                 while(_i < nxt.size() && nxt[_i] == cur) _i++, tot--;
      |                       ~~~^~~~~~~~~~~~
popeala.cpp:109: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]
  109 |                 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;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9044 KB Output is correct
2 Correct 7 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 613 ms 9092 KB Output is correct
2 Correct 512 ms 9092 KB Output is correct
3 Incorrect 576 ms 9088 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2080 ms 9044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9044 KB Output is correct
2 Correct 7 ms 9044 KB Output is correct
3 Correct 613 ms 9092 KB Output is correct
4 Correct 512 ms 9092 KB Output is correct
5 Incorrect 576 ms 9088 KB Output isn't correct
6 Halted 0 ms 0 KB -