Submission #44757126


Source Code Expand

#include<cstdio>
#include<cstring>
using namespace std;
#define Ed for(int i=h[x];~i;i=ne[i])
#define Ls(i,l,r) for(int i=l;i<r;++i)
#define Rs(i,l,r) for(int i=l;i>r;--i)
#define Le(i,l,r) for(int i=l;i<=r;++i)
#define Re(i,l,r) for(int i=l;i>=r;--i)
#define L(i,l) for(int i=0;i<l;++i)
#define E(i,l) for(int i=1;i<=l;++i)
#define W(t) while(t--)
#define Wh while

const int N=2010;
int n,m,r[N],c[N],cntr,cntc;
char s[N][N];
bool str[N],stc[N];
bool change(){
    cntr=cntc=0;
    E(i, n){
        if(str[i])continue;
        bool f=1;
        int cnt=0;
        char lst=0;
        E(j, m){
            if(s[i][j]){
                ++cnt;
                if(!lst)lst=s[i][j];
                else if(s[i][j]!=lst){
                    f=0;
                    break;
                }
            }
        }
        if(f&&cnt>=2)str[i]=1,r[++cntr]=i;
    }
    E(i, m){
        if(stc[i])continue;
        bool f=1;
        int cnt=0;
        char lst=0;
        E(j, n){
            if(s[j][i]){
                ++cnt;
                if(!lst)lst=s[j][i];
                else if(s[j][i]!=lst){
                    f=0;
                    break;
                }
            }
        }
        if(f&&cnt>=2)stc[i]=1,c[++cntc]=i;
    }
    // printf("%d %d\n",cntr,r[cntr]);
    E(i, cntr)memset(s[r[i]],0,m+1);
    E(i, cntc){
        E(j, n)s[j][c[i]]=0;
    }
    if(cntr||cntc)return 1;
    return 0;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    #endif
    scanf("%d%d",&n,&m);
    E(i, n)scanf("%s",s[i]+1);
    while(change());
    int ans=0;
    E(i, n)
        E(j, m)ans+=s[i][j]!=0;
    printf("%d",ans);
    return 0;
}

Submission Info

Submission Time
Task D - Magical Cookies
User WUSICHENG
Language C++ 20 (gcc 12.2)
Score 0
Code Size 1740 Byte
Status TLE
Exec Time 2207 ms
Memory 5668 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:66:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:67:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |     E(i, n)scanf("%s",s[i]+1);
      |            ~~~~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 34
TLE × 2
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt
Case Name Status Exec Time Memory
sample00.txt AC 0 ms 1620 KiB
sample01.txt AC 0 ms 1728 KiB
sample02.txt AC 0 ms 1760 KiB
testcase00.txt AC 11 ms 5664 KiB
testcase01.txt AC 14 ms 5576 KiB
testcase02.txt AC 15 ms 5648 KiB
testcase03.txt AC 17 ms 5604 KiB
testcase04.txt AC 20 ms 5416 KiB
testcase05.txt AC 12 ms 5576 KiB
testcase06.txt AC 27 ms 5504 KiB
testcase07.txt AC 40 ms 5580 KiB
testcase08.txt AC 46 ms 5520 KiB
testcase09.txt AC 75 ms 5648 KiB
testcase10.txt AC 12 ms 5524 KiB
testcase11.txt AC 45 ms 5560 KiB
testcase12.txt AC 56 ms 5624 KiB
testcase13.txt AC 59 ms 5316 KiB
testcase14.txt AC 81 ms 5648 KiB
testcase15.txt AC 13 ms 5584 KiB
testcase16.txt AC 46 ms 5520 KiB
testcase17.txt AC 82 ms 5508 KiB
testcase18.txt AC 85 ms 5468 KiB
testcase19.txt AC 96 ms 5504 KiB
testcase20.txt AC 15 ms 5668 KiB
testcase21.txt AC 72 ms 5392 KiB
testcase22.txt AC 79 ms 5580 KiB
testcase23.txt AC 95 ms 5284 KiB
testcase24.txt AC 102 ms 5560 KiB
testcase25.txt TLE 2207 ms 5528 KiB
testcase26.txt TLE 2207 ms 5452 KiB
testcase27.txt AC 159 ms 5564 KiB
testcase28.txt AC 163 ms 5536 KiB
testcase29.txt AC 19 ms 5536 KiB
testcase30.txt AC 21 ms 5588 KiB
testcase31.txt AC 20 ms 5656 KiB
testcase32.txt AC 23 ms 5536 KiB