답안 #793771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793771 2023-07-26T06:29:44 Z 반딧불(#10057) Triangle Collection (CCO23_day2problem3) C++17
0 / 25
4000 ms 9636 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, q;
ll arr[200002];
ll val[200002];

set<int> odd, even;
ll ans;

void makeTriangle(int a, int b, int t){
    ans += t;
    if(val[a]%2) odd.erase(a); else even.erase(a);
    if(a!=b) {if(val[b]%2) odd.erase(b); else even.erase(b);}
    val[a] -= t*2, val[b] -= t;
    if(val[a]) {if(val[a]%2) odd.insert(a); else even.insert(a);}
    if(a!=b && val[b]) {if(val[b]%2) odd.insert(b); else even.insert(b);}
}

void solve(){
    ans = 0;
    odd.clear(), even.clear();
    for(int i=1; i<=n; i++){
        val[i] = arr[i];
        if(val[i]){
            if(val[i]%2) odd.insert(i);
            else even.insert(i);
        }
    }
    for(int i=1; i<=n; i++){
        while(val[i] >= 2){
            /// ���� odd���� ã�ƺ���
            if(!odd.empty() && *odd.begin() < i*2){
                int x = *odd.begin();
                makeTriangle(i, x, 1);
                if(val[i]==2) break;
                continue;
            }
            /// �� ���� ���� ���� even�� ���Ѵ�.
            if(even.empty() || *even.begin() >= i*2){
                if(val[i]==2) break;
                continue;
            }
            int x = *even.begin();
            if(x == i && val[i] == 2){
                if((int)even.size() == 1 || *next(even.begin()) >= i*2){
                    if(val[i]==2) break;
                    continue;
                }
                x = *next(even.begin());
            }
            int k;
            if(i==x) k = val[i] / 3;
            else k = min(val[i] / 2, val[x]);
            makeTriangle(i, x, k);
        }
    }
    printf("%lld\n", ans);
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
    while(q--){
        int x; ll v;
        scanf("%d %lld", &x, &v);
        arr[x] += v;
        solve();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:66:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         scanf("%d %lld", &x, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 11 ms 324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 11 ms 324 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 388 KB Output is correct
2 Correct 280 ms 340 KB Output is correct
3 Correct 146 ms 584 KB Output is correct
4 Execution timed out 4066 ms 9636 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 319 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 11 ms 324 KB Output isn't correct
4 Halted 0 ms 0 KB -