/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 3ms 328.0 KiB
#4 Accepted 3ms 328.0 KiB
#5 Accepted 4ms 568.0 KiB
#6 Accepted 3ms 348.0 KiB
#7 Accepted 2ms 332.0 KiB

Code

// #include <iostream>
// #include <string>
// #include <vector>
// #include <set>
// #include <unordered_set>
// #include <map>
// #include <list>
// #include <algorithm>
// #include <numeric>
// #include <cmath>
#include <bits/stdc++.h>
#define ll long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define vint vector<int>
#define vll vector<ll>
#define vch vector<char>
#define vstr vector<string>
#define u_set unordered_set
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
using namespace std;

void debug()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

void solve();

int32_t main()
{
    fast;
    // debug();
    int TestCase = 1;
    cin >> TestCase;
    while (TestCase--)
        solve();
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vint vect;
    ll sum = 0;
    int a0 = 0;
    int a1 = 0;
    int a2 = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        sum += (x % 3);
        if (x % 3 == 1)
        {
            a1++;
        }
        if (x % 3 == 2)
        {
            a2++;
        }
    }
    if (sum % 3 == 0)
    {
        cout << n << '\n';
    }
    if (sum % 3 == 1)
    {
        if (a1 >= 1)
        {
            cout << n - 1 << '\n';
        }
        else
        {
            cout << n - 2 << '\n';
        }
    }
    if (sum % 3 == 2)
    {
        if (a2 >= 1)
        {
            cout << n - 1 << '\n';
        }
        else
        {
            cout << n - 2 << '\n';
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1013 Divisible by 3
Contest
Brain booster - 1
Language
C++20 (G++ 13.2.0)
Submit At
2023-12-31 15:11:43
Judged At
2024-11-11 03:45:54
Judged By
Score
100
Total Time
4ms
Peak Memory
568.0 KiB