QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120132#6138. Function and Functionhos_lyricAC ✓11ms3680kbC++142.1kb2023-07-06 14:09:052023-07-06 14:09:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 14:09:06]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:3680kb
  • [2023-07-06 14:09:05]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


constexpr int A[10] = {
  1, 0, 0, 0, 1,
  0, 1, 0, 2, 1,
};

int calc(int x) {
  int ret = 0;
  do {
    ret += A[x % 10];
    x /= 10;
  } while (x > 0);
  return ret;
}

constexpr int V = 20;
int F[V][V + 1];

int main() {
  for (int u = 0; u < V; ++u) {
    F[u][0] = u;
    for (int k = 1; k <= V; ++k) {
      F[u][k] = calc(F[u][k - 1]);
    }
// cerr<<u<<": ";pv(F[u],F[u]+V+1);
  }
  
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    int X, K;
    scanf("%d%d", &X, &K);
    
    int x = X;
    int k = K;
    for (; k > 0; ) {
      if (x < V) {
        if (k > V) {
          k = (V - 1) + (k - (V - 1)) % 2;
        }
        x = F[x][k];
        k = 0;
      } else {
        x = calc(x);
        --k;
      }
    }
    printf("%d\n", x);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3520kb

input:

6
123456789 1
888888888 1
888888888 2
888888888 999999999
98640 12345
1000000000 0

output:

5
18
2
0
0
1000000000

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 11ms
memory: 3680kb

input:

100000
579268184 2
120252252 777743676
255650198 1
152055433 207664522
137430584 754115403
646417467 164848484
743551976 0
0 408695577
363072674 569574204
464290891 0
761830281 3
0 1
49176280 2
791182580 0
474930784 3
402374924 0
739903247 91553857
0 2
688106229 2
65907033 152261569
875191599 3
5319...

output:

0
0
5
0
1
1
743551976
1
1
464290891
0
1
1
791182580
1
402374924
0
0
2
0
1
1
2
1
0
0
0
3
0
0
0
1
0
0
1
0
2
0
1
1
1
0
1
0
0
0
0
0
0
1
55349255
486354015
1
1
0
1
1
0
1
1
0
1
0
9
0
1
1
0
0
1
0
1
1
1
0
0
0
0
25600152
0
0
1
22903397
705086250
771453912
1
1
0
0
1
0
1
1
1
2
1
1
1
1
1
1
6
3
3
1
0
1
0
1
86248...

result:

ok 100000 numbers