全TLE求调

P1319 压缩技术

AL_lS @ 2024-10-11 11:16:27

#include <iostream>  
using namespace std;
int main() {
    int m, n,i=0,r=0,q=0;
    cin >> n;
    while (q <= n * n) {
            cin >> m;
            for (int p = 1; p <= m; p++) {
                q++;
                if (q % n == 0) {
                    cout << endl;
                }
                printf("%d", r);
            }
            m = 0;
            if (i % 2 == 0) {
                r = 1;
            }
            else {
                r = 0;
            }
            i++;
    }
}

先谢过大佬们了><


by 阿丑 @ 2024-10-11 11:42:15

@AL_lS while (q <= n * n) 改成 while (q < n * n),因为最后 q 会等于 n*n,就退不出循环了


by AL_lS @ 2024-10-11 23:10:14

@阿丑 全tle修正边界跳出循环,微调下换行逻辑后全ac了,谢谢佬!


|