QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129545#6300. Best Carry Player 2sinsop90WA 1ms3596kbC++143.2kb2023-07-22 20:30:242023-07-22 20:30:28

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-22 20:30:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3596kb
  • [2023-07-22 20:30:24]
  • 提交

answer

#include <bits/stdc++.h>
#define int __int128
using namespace std;
namespace FastIO {
	struct IO {
	    char ibuf[(1 << 20) + 1], *iS, *iT, obuf[(1 << 20) + 1], *oS;
	    IO() : iS(ibuf), iT(ibuf), oS(obuf) {} ~IO() { fwrite(obuf, 1, oS - obuf, stdout); }
		#if ONLINE_JUDGE
		#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
		#else
		#define gh() getchar()
		#endif
		inline bool eof (const char &ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == 't' || ch == EOF; }
	    inline long long read() {
	        char ch = gh();
	        long long x = 0;
	        bool t = 0;
	        while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
	        while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
	        return t ? ~(x - 1) : x;
	    }
	    inline void read (char *s) {
	    	char ch = gh(); int l = 0;
	    	while (eof(ch)) ch = gh();
	    	while (!eof(ch)) s[l++] = ch, ch = gh();
	    }
	    inline void read (double &x) {
	    	char ch = gh(); bool t = 0;
	    	while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
	    	while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = gh();
	    	if (ch != '.') return t && (x = -x), void(); ch = gh();
	    	for (double cf = 0.1; '0' <= ch && ch <= '9'; ch = gh(), cf *= 0.1) x += cf * (ch ^ 48);
	    	t && (x = -x);
	    }
	    inline void pc (char ch) {
	    	#ifdef ONLINE_JUDGE
	    	if (oS == obuf + (1 << 20) + 1) fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; 
	    	*oS++ = ch;
	    	#else
	    	putchar(ch);
	    	#endif
		}
		template<typename _Tp>
	    inline void write (_Tp x) {
	    	static char stk[64], *tp = stk;
	    	if (x < 0) x = ~(x - 1), pc('-');
			do *tp++ = x % 10, x /= 10;
			while (x);
			while (tp != stk) pc((*--tp) | 48);
	    }
	    inline void write (char *s) {
	    	int n = strlen(s);
	    	for (int i = 0; i < n; i++) pc(s[i]);
	    }
	} io;
	inline long long read () { return io.read(); }
	template<typename Tp>
	inline void read (Tp &x) { io.read(x); }
	template<typename _Tp>
	inline void write (_Tp x) { io.write(x); }
}
using namespace FastIO;
int T, n, k, f[38][38][2], vis[38][38][2];
void solve() {
	n = read(), k = read();
	int now = 1;
	for(int i = 0;i<= 36;i++) for(int j = 0;j <= k + 1;j++) for(int op = 0;op <= 1;op ++) f[i][j][op] = 2e37;
	for(int i = 1;i <= 36;i++) {
		int g = n / now % 10;
		if(g) f[i][1][1] = min(f[i][1][1], now * (10 - g)), vis[i][1][1] = 1;
		if(g - 9) f[i][0][0] = min(f[i][0][0], now), vis[i][0][0] = 1;  
		for(int j = 0;j <= k;j++) {
			if(g && vis[i - 1][j][0]) {
				f[i][j + 1][1] = min(f[i][j + 1][1], f[i - 1][j][0] + now * (10 - g)), vis[i][j + 1][1] = 1;
			}
			if(vis[i - 1][j][0]) f[i][j][0] = min(f[i][j][0], f[i - 1][j][0]), vis[i][j][0] = 1;
			if(vis[i - 1][j][1]) f[i][j + 1][1] = min(f[i][j + 1][1], f[i - 1][j][1] + now * (10 - 1 - g)), vis[i][j + 1][1] = 1;
			if(g != 9 && vis[i - 1][j][1]) f[i][j][0] = min(f[i][j][0], f[i - 1][j][1]), vis[i][j][0] = 1;
		}
		now *= 10;
		
	}
	if(!vis[36][k][0] && !vis[36][k][1]) write(-1), putchar('\n');
	else {
		write(min(f[36][k][1], f[36][k][0]));
		putchar('\n');
	}
}
signed main() {
	T = read();
	while(T --) solve();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3596kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:





1543229999999999876543229910

result:

wrong answer 1st lines differ - expected: '1', found: ''