QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133149 | #6630. Triangle Collection | penguinman# | 0 | 1173ms | 3852kb | C++17 | 1.9kb | 2023-08-01 16:29:27 | 2024-07-04 01:06:52 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define ln "\n"
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define all(a) a.begin(), a.end()
#define pb emplace_back
#define mp std::make_pair
constexpr ll inf = (1ll<<60);
int main(){
ll N,Q; cin >> N >> Q;
vi C(N);
rep(i,0,N) cin >> C[i];
while(Q--){
ll l,d; cin >> l >> d;
C[l-1] += d;
vi memC = C;
ll ans = 0;
std::set<ll> remain;
remain.insert(inf);
rep(i,0,N){
if(C[i]) remain.insert(i);
}
rep(i,0,N){
if(remain.count(i)) remain.erase(i);
if(C[i]%3 == 0){
ans += C[i]/3;
C[i] = 0;
continue;
}
if(C[i]%3 == 1){
if(C[i] == 1){
C[i] = 0;
continue;
}
ans += C[i]/3-1;
C[i] = 4;
}
if(C[i]%3 == 2){
ans += C[i]/3;
C[i] = 2;
}
rep(j,0,C[i]/2){
ll idx = -1;
ll max = -1;
for(auto el: remain){
if(el > 2*i) break;
if(max < C[el]){
max = C[el];
idx = el;
}
}
if(idx == -1) break;
C[idx]--;
ans++;
if(C[idx] == 0) remain.erase(idx);
}
C[i] = 0;
}
cout << ans << ln;
C = memC;
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
1 23 1485 1 -12 1 -30 1 -20 1 6 1 24 1 5 1 31 1 14 1 -34 1 -22 1 -45 1 37 1 46 1 9 1 22 1 -9 1 9 1 -46 1 -47 1 39 1 36 1 -36 1 50
output:
491 481 473 475 483 486 495 501 489 481 466 479 495 498 504 501 504 490 473 486 498 486 504
result:
wrong answer 3rd numbers differ - expected: '474', found: '473'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1173ms
memory: 3852kb
input:
1999 2000 1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...
output:
330 330 330 331 331 331 331 330 330 330 330 331 331 331 332 332 331 331 331 331 331 330 331 330 330 330 331 331 331 331 331 331 331 330 331 330 330 329 329 330 330 329 330 330 330 330 330 330 330 330 330 330 330 330 330 330 330 330 330 329 329 329 329 329 329 329 329 329 328 329 329 329 328 328 328 ...
result:
wrong answer 1st numbers differ - expected: '660', found: '330'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 924ms
memory: 3580kb
input:
2000 1999 0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...
output:
496 496 496 496 496 496 496 496 496 497 497 497 497 497 497 498 497 497 497 498 497 498 497 497 496 496 496 496 495 495 496 496 496 496 496 496 495 495 495 495 495 495 494 494 494 494 493 493 493 493 493 493 493 493 493 493 493 493 493 493 493 493 493 494 493 494 494 494 494 494 494 494 494 493 493 ...
result:
wrong answer 1st numbers differ - expected: '666', found: '496'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%