145042025-01-12 21:15:47sarminTáblajáték 2 (70 pont)cpp17Részben helyes 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base49/70
1Elfogadva0/01ms508 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms316 KiB
6Részben helyes1/31ms316 KiB
7Elfogadva3/31ms316 KiB
8Elfogadva3/31ms316 KiB
9Elfogadva3/31ms316 KiB
10Elfogadva3/31ms316 KiB
11Elfogadva3/31ms316 KiB
12Részben helyes1/31ms508 KiB
13Elfogadva3/31ms316 KiB
14Elfogadva3/31ms564 KiB
15Elfogadva4/41ms316 KiB
16Részben helyes1/41ms420 KiB
17Elfogadva4/41ms316 KiB
18Elfogadva4/41ms316 KiB
19Részben helyes1/41ms316 KiB
20Részben helyes1/41ms552 KiB
21Részben helyes1/41ms564 KiB
22Részben helyes1/41ms548 KiB
23Részben helyes1/31ms372 KiB