#24227: 優化IO


fire5386 (Penguin07)

School : 國立清華大學
ID : 115822
IP address : [1.160.167.109]
Last Login :
2023-01-31 21:59:18
b938. kevin 愛殺殺 | From: [61.230.2.126] | Post Date : 2021-01-28 22:22

成功用優化壓到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

 
ZeroJudge Forum