Submission #313913

# Submission time Handle Problem Language Result Execution time Memory
313913 2020-10-17T09:43:12 Z phathnv Elder (COCI19_elder) C++11
50 / 50
1 ms 368 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "ELDER"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

char s;
int n;
bool d[26];

void readInput(){
    cin >> s >> n;
}

void solve(){
    int cnt = 1;
    int cur = s - 'A';
    d[cur] = 1;
    for(int i = 1; i <= n; i++){
        char a, b;
        cin >> a >> b;
        a -= 'A';
        b -= 'A';
        if (b != cur)
            continue;
        cur = a;
        if (!d[cur])
            cnt++;
        d[cur] = 1;
    }
    cout << (char) (cur + 'A') << '\n' << cnt;
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message

elder.cpp: In function 'int main()':
elder.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
elder.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   43 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 368 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct