/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Wrong Answer 21ms 564.0 KiB
#3 Wrong Answer 21ms 584.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
 
const int N = 3e5 + 9;
using ll = long long;
 
void solve() {
  int n; cin >> n;
  map<int, int> mp;

  for(int i=0; i<n; i++) {
    int e; cin >> e;
    mp[e]++;
  }

  int one_ct = mp[1] , m_ct = mp[-1] , z_ct = mp[0] % 3;
  // cout << one_ct << ' ' << m_ct << ' ' << z_ct << endl;
  
  int s = 0;
  if(z_ct > 0 && m_ct == 0 && z_ct == 0) {
    cout << s << endl;
    return;
  }
  while(one_ct >= 1 && m_ct >= 2) {
    m_ct -= 2;
    one_ct -= 1;
    s += 1;
  }

  if(m_ct == 1) {
    if(z_ct == 0) s-= 1;
    cout << s << endl;
    return;
  }
  if(m_ct == 0) {
    if(z_ct) s -= 1;
    cout << s << endl;
    return;
  }

  if(one_ct == 0) {
    if(z_ct == 1) m_ct -= 2;
    if(z_ct == 2) m_ct -= 1;
    s += -1 * (m_ct / 3);
    cout << s << endl;
    return;
  }







  
}
 
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 16:33:06
Judged At
2025-01-02 16:33:06
Judged By
Score
1
Total Time
21ms
Peak Memory
768.0 KiB