成功用優化壓到1秒內 AC (0.9s, 47.1MB)
可以使用getchar_unlocked()加速讀取和putchar_unlocked()加速輸出,其他的部分我用STL的set操作
優化程式碼:
void readint(int* loc) {
char c;
int ret = 0;
while(1) {
c = getchar_unlocked();
if(c >= '0' && c <= '9')
ret = (ret * 10) + (c - '0');
else {
*loc = ret;
return;
}
}
}
void printint(int n) {
char c;
int temp = n;
int arr[10];
int i;
for(i = 0, temp = n; temp > 0; i++, temp /= 10)
arr[i] = temp % 10;
i--;
while(i >= 0)
putchar_unlocked(arr[i] + '0'), i--;
putchar_unlocked('\n');
return;
}
void printstr(string s) {
for(int i = 0; i < s.size(); i++)
putchar_unlocked(s[i]);
putchar_unlocked('\n');
return;
}
完整程式碼:
https://66lemon66.blogspot.com/2021/01/zerojudge-b938-kevin-c.html