Codeforces 1131D - Gourmet choice

题目链接:传送门

题面:

D. Gourmet choice

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review  — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the dishes are different, because Mr. Apple doesn't like to eat the same food. For each pair of dishes from different days he remembers exactly which was better, or that they were of the same quality. After this the gourmet evaluates each dish with a positive integer.

Once, during a revision of a restaurant of Celtic medieval cuisine named «Poisson», that serves chestnut soup with fir, warm soda bread, spicy lemon pie and other folk food, Mr. Apple was very pleasantly surprised the gourmet with its variety of menu, and hence ordered too much. Now he's confused about evaluating dishes.

The gourmet tasted a set of nn dishes on the first day and a set of mm dishes on the second day. He made a table aa of size n×mn×m, in which he described his impressions. If, according to the expert, dish ii from the first set was better than dish jj from the second set, then aijaij is equal to ">", in the opposite case aijaij is equal to "<". Dishes also may be equally good, in this case aijaij is "=".

Now Mr. Apple wants you to help him to evaluate every dish. Since Mr. Apple is very strict, he will evaluate the dishes so that the maximal number used is as small as possible. But Mr. Apple also is very fair, so he never evaluates the dishes so that it goes against his feelings. In other words, if aijaij is "<", then the number assigned to dish ii from the first set should be less than the number of dish jj from the second set, if aijaij is ">", then it should be greater, and finally if aijaij is "=", then the numbers should be the same.

Help Mr. Apple to evaluate each dish from both sets so that it is consistent with his feelings, or determine that this is impossible.

Input

The first line contains integers nn and mm (1≤n,m≤10001≤n,m≤1000) — the number of dishes in both days.

Each of the next nn lines contains a string of mm symbols. The jj-th symbol on ii-th line is aijaij. All strings consist only of "<", ">" and "=".

Output

The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwise.

If case an answer exist, on the second line print nn integers — evaluations of dishes from the first set, and on the third line print mmintegers — evaluations of dishes from the second set.

Examples

input

3 4
>>>>
>>>>
>>>>

output

Yes
2 2 2 
1 1 1 1 

input

3 3
>>>
<<<
>>>

output

Yes
3 1 3 
2 2 2 

input

3 2
==
=<
==

output

No

题意描述:

       Mr. Apple是一名美食家,在一家餐厅吃了两套菜,第一套n个菜,第二套m个菜,给这些菜评了分,现在给你n*m的矩阵,由'>','<'和'='构成。s[i][j]表示第一套菜的第i个菜跟第二套菜的第j个菜相比较的结果。要你求出这些菜的评分,最大的评分越小越好。

题面分析:

       因为这道题目要求最大评分最小,那么,我们先假定比较相差都是一分和零分,把分数比这个位置好的或等于的边都存进来,价值分别为1和0,然后暴力dfs就行了,具体操作开代码。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
vector<int>Q[maxn];  //存放评分比i好或等于的边
vector<int>M[maxn];  //跟Q先对应,好就是1,等于就是0
int n, m;
int vis[maxn], dis[maxn];
char s[maxn];
void dfs(int u){
    vis[u] = 1;   //用来判断冲突情况
    for(int i=0;i<Q[u].size();++i){
        int v = Q[u][i], val = M[u][i];
        if(dis[v] < dis[u]+val){     //dis[v]应该等于dis[u]+val的,如果小于,重新赋值
            if(vis[v]){     //不能放外面,因为可能有等于的情况
                cout << "No" << endl; exit(0);
            }
            dis[v] = dis[u] + val;
            dfs(v);
        }
    }
    vis[u] = 0;
}
int main(){
    cin >> n >> m;
    for(int i=0;i<n;++i){
        scanf("%s", s);
        for(int j=0;j<m;++j){
            if(s[j] == '='){   //上面已经说明
                Q[i].push_back(j+n); M[i].push_back(0);
                Q[j+n].push_back(i); M[j+n].push_back(0);
            }else if(s[j] == '>'){
                Q[j+n].push_back(i); M[j+n].push_back(1);
            }else {
                Q[i].push_back(j+n); M[i].push_back(1);
            }
        }
    }
    for(int i=0;i<n+m;++i) dfs(i);  //要找到最低分开始dfs,所以要循环一遍
    cout << "Yes" << endl;
    for(int i=0;i<n-1;++i) printf("%d ", dis[i]+1); printf("%d\n", dis[n-1]+1);
    for(int j=n;j<n+m-1;++j) printf("%d ", dis[j]+1); printf("%d\n", dis[n+m-1]+1);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值