#54906: 所以錯在哪裡???


edwardlin@apps.ntpc.edu.tw (╰(*°▽°*)╯╰(*°▽°*)╯╰(*°▽°*)╯)


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <string>
#include <vector>

using namespace std;

int main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);

int n, m;
cin >> n >> m;
int a[n+1][m+1], point = 0;
for(int y=1; y<=n; y++)
        for(int x=1; x<=m; x++)
            cin >> a[y][x];
    bool stop = 0;
    while(!stop)
    {
        bool s=0;
        for(int y=1; y<=n; y++)
        {
            int last = a[y][1];
            for(int x=2; x<=m; x++)
            {
                if(a[y][x] != -1)
                {
                    if(a[y][x] == last)
                    {
                        point += a[y][x];
                        s = 1;
                        a[y][x] = -1, a[y][x-1] = -1;
                    }
                    last = a[y][x];
                }
            }
        }
        for(int x=1; x<=m; x++)
        {
            int last = a[1][x];
            for(int y=2; y<=n; y++)
            {
                if(a[y][x] != -1)
                {
                    if(a[y][x] == last)
                    {
                        point += a[y][x];
                        s = 1;
                        a[y][x] = -1, a[y-1][x] = -1;
                    }
                    last = a[y][x];
                }
            }
        }
        if(s == 0)
            stop = 1;
    }
    cout << point;
return 0;
}


錯在哪