/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 1ms 320.0 KiB
#3 Wrong Answer 2ms 324.0 KiB

Code

#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main() {
    faster
    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;
        int arr[n + 7];
        int sum = 0;
        for(int i = 0; i < n; i++) {
            cin >> arr[i];
            sum+=arr[i];
        }
        if(sum%3==0) {
            cout << n << endl;
            continue;
        }

        int ex=sum%3;
        bool found = false;

        for(int i=1;i<=n;i++) {
            int sum2=0;

            for(int j=0;j<i;j++) {
                sum2 += arr[j];
            }

            if(sum2 % 3 == ex) {
                cout << n - i << endl;
                found = true;
                break;
            }
        }

        if(!found) {
            cout << 0 << endl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1013 Divisible by 3
Contest
Brain booster - 1
Language
C++17 (G++ 13.2.0)
Submit At
2023-12-31 14:15:47
Judged At
2024-11-11 03:46:21
Judged By
Score
10
Total Time
2ms
Peak Memory
324.0 KiB