답안 #1007568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007568 2024-06-25T08:01:04 Z andecaandeci Lasers (NOI19_lasers) C++17
10 / 100
37 ms 24264 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 998244353;
const ll MAXN = 5e5 + 5;
const ll LOG = 31;
#define vll vector <ll>
#define pll pair <ll, ll>
#define fi first
#define se second
#define endl '\n'

ll n, m;
ll b [MAXN], pf [MAXN], sf [MAXN];
vector <pll> kos, u, v;
vll ans;

void solve(){
    cin >> n >> m;
    for(ll i = 1; i <= m; i++){
        ll z; cin >> z;
        for(ll j = 1; j <= z; j++) cin >> b[j];
        pf[0] = 0, sf[z+1] = 0;
        for(ll j = 1; j <= z; j++) pf[j] = pf[j-1] + b[j];
        for(ll j = z; j >= 1; j--) sf[j] = sf[j+1] + b[j];
        kos.clear();
        for(ll j = 1; j <= z; j++){
            ll l = pf[j-1]+1, r = n - sf[j+1];
            if(l+b[j]-1 >= r-b[j]+1){
                kos.push_back({r-b[j], l});
                kos.push_back({r, l+b[j]});
            }
            else kos.push_back({r, l});
        }
        sort(kos.begin(), kos.end());
        u.clear();
        u.push_back({0, 0});
        ll ans = 0;
        ll vl = -INF, vr = -INF;
        for(auto x : kos){
            // cout << x.se << " << " << x.fi << endl;
            ll l = x.se, r = x.fi;
            if(l <= vr) vr = r;
            else{
                if(vr != -INF) u.push_back({vl, vr});
                vl = l, vr = r;
            }
        }
        if(vr != -INF) u.push_back({vl, vr});
        u.push_back({n+1, n+1});
        for(ll j = 1; j < u.size(); j++){
            ll l = u[j-1].se+1, r = u[j].fi-1;
            if(l <= r) v.push_back({r, l});
        }
    }
    sort(v.begin(), v.end());
    // for(auto x : v){
    //     cout << x.se << " " << x.fi << endl;
    // }
    ll ans = 0;
    ll vl = -INF, vr = -INF;
    for(auto x : v){
        ll l = x.se, r = x.fi;
        if(l <= vr) vr = r;
        else{
            if(vr != -INF) ans += vr - vl + 1;
            vl = l, vr = r;
        }
    }
    if(vr != -INF) ans += vr - vl + 1;
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // ll t; cin >> t;
    // while(t--){
        solve();
    // }
}

Compilation message

lasers.cpp: In function 'void solve()':
lasers.cpp:55:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(ll j = 1; j < u.size(); j++){
      |                       ~~^~~~~~~~~~
lasers.cpp:42:12: warning: unused variable 'ans' [-Wunused-variable]
   42 |         ll ans = 0;
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Incorrect 1 ms 4440 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 24264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 24264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Incorrect 1 ms 4440 KB Output isn't correct
12 Halted 0 ms 0 KB -