Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <math.h>
- #include <cmath>
- #include <set>
- #include <map>
- #include <cassert>
- #include <algorithm>
- #include <ctime>
- #include <iomanip>
- //#include <thread>
- using namespace std;
- #define mp make_pair
- #define sz size()
- #define all(x) x.begin(),x.end()
- #define forn(i,n) for (int i = 0; i<int(n); i++)
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> ii;
- const int INF = 1e9 + 7;
- const ld EPS = 1e-14;
- //#define DEBUG
- #ifdef DEBUG
- #define PL(x) cout<<#x<<" = "<<x<<endl
- #define PR(x) cout<<#x<<" = "<<x<<" "
- #else
- #define PL(x) {}
- #define PR(x) {}
- #endif
- ll opt[] = { 0, 1, 1, 1, 2, 1, 2, 1, 1, 3 };
- ll len[] = { 0, 1, 1, 1, 2, 1, 2, 2, 2, 3 };
- ll dpows[20];
- void init(){
- ll num = 1;
- for (int i = 0; i<19; i++){
- dpows[i] = num;
- num *= 10ll;
- }
- }
- vector<ll> getDeg(ll w){
- vector<ll> ans;
- while (w > 0){
- ans.push_back(w % 10ll);
- w /= 10ll;
- }
- return ans;
- }
- void solve(){
- ll w,c;
- ll numNote = 0, numWay = 1;
- cin>>w>>c;
- if (w % 1000ll != 0){
- cout << 0 << endl;
- return;
- }
- else{
- w /= 1000ll;
- }
- vector<ll> wdeg = getDeg(w);
- if (wdeg.sz > c+1){
- ll num = (w % (dpows[c + 2]))/(dpows[c]);
- if (num == 11){
- numWay = 2ll;
- }
- ll kol = w / (dpows[c+1]);
- kol *= 2ll;
- numNote += kol;
- }
- c = min(c,(ll)wdeg.sz - 1ll);
- while (c >= 0){
- if (wdeg[c] == 0){
- c--;
- continue;
- }
- else{
- numWay *= opt[wdeg[c]];
- numNote += len[wdeg[c]];
- c--;
- }
- }
- cout << numNote << " " << numWay << endl;
- }
- int main(){
- #ifdef DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- init();
- int test;
- cin >> test;
- for (int i = 0; i < test; i++){
- solve();
- }
- #ifdef DEBUG
- cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement