145042025-01-12 21:15:47sarminTáblajáték 2 (70 pont)cpp17Partially correct 49/701ms564 KiB
// Created by Armin on 1/12/2025.
// See on https://njudge.hu/problemset/main/NT23_Tablajatek2/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<int, int>;

void convertToTernary(ll n) {
  if (n == 0) return;
  const ll x = n % 3;
  n /= 3;
  if (x < 0) n++;
  convertToTernary(n);
  cout << x;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    int n; cin >> n;
    ll i = 0, j = 0;
    for (int k = 0; k < n; k++) {
        int x; cin >> x;
        if (x == 0) {
          i++;
          j *= 3;
        } else if (x == 1) {
          i++;
          j = 3*j+1;
        } else if (x == 2) {
          i++;
          j = 3*j+2;
        } else if (x == 3) {
          i--;
          j /= 3;
        } else if (x == 4) {
          j--;
        } else if (x == 5) {
          j++;
        }
    }
    cout << i << '\n';
    convertToTernary(j);
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base49/70
1Accepted0/01ms508 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Partially correct1/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/31ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Partially correct1/31ms508 KiB
13Accepted3/31ms316 KiB
14Accepted3/31ms564 KiB
15Accepted4/41ms316 KiB
16Partially correct1/41ms420 KiB
17Accepted4/41ms316 KiB
18Accepted4/41ms316 KiB
19Partially correct1/41ms316 KiB
20Partially correct1/41ms552 KiB
21Partially correct1/41ms564 KiB
22Partially correct1/41ms548 KiB
23Partially correct1/31ms372 KiB