Submission #67612

# Submission time Handle Problem Language Result Execution time Memory
67612 2018-08-15T06:34:44 Z win11905 Igra (COCI17_igra) C++11
100 / 100
6 ms 616 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 5e3+5;

int n, a[3], b[3];
char A[N], B[N];

bool check() {
    for(int i = 0; i <= a[0]; ++i) {
        int x = b[1] - i;
        int y = b[2] - (a[0] - i);
        if(x < 0 || y < 0) continue;
        if(x <= a[2] && y <= a[1]) return true;
    }
    return false;
}

int main() {
    scanf("%d", &n);
    scanf("%s %s", B+1, A+1);
    for(int i = 1; i <= n; ++i) {
        A[i] -= 'a', B[i] -= 'a';
        a[A[i]]++, b[B[i]]++;
    }
    for(int i = 1; i <= n; ++i) {
        a[A[i]]--;
        for(int j = 0; j < 3; ++j) {
            b[j]--;
            if(A[i] != j && check()) {
                printf("%c", j+'a');
                break;
            }
            b[j]++;
        }    
    }
}

Compilation message

igra.cpp: In function 'int main()':
igra.cpp:24:15: warning: array subscript has type 'char' [-Wchar-subscripts]
         a[A[i]]++, b[B[i]]++;
               ^
igra.cpp:24:26: warning: array subscript has type 'char' [-Wchar-subscripts]
         a[A[i]]++, b[B[i]]++;
                          ^
igra.cpp:27:15: warning: array subscript has type 'char' [-Wchar-subscripts]
         a[A[i]]--;
               ^
igra.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
igra.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s %s", B+1, A+1);
     ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 3 ms 616 KB Output is correct
8 Correct 3 ms 616 KB Output is correct
9 Correct 6 ms 616 KB Output is correct
10 Correct 5 ms 616 KB Output is correct